In my project, I need to perform some operation, when a Virtual Machine does not start within 10 minutes. In order to test the functionality, I want to slow down the Running state of Virtual Machine or shutdown/poweroff the machine, so that the status of Virtual Machine becomes Stopped. How to slow down the Running state of ubuntu Virtual Machine ?
I used cloud-init script and tried the below :
#cloud-config
bootcmd:
- sleep 600
#cloud-config
runcmd:
- [ sh, -c, "sleep 1000" ]
#cloud-config
runcmd:
- [sh, -c, "counter=1; while [ $counter -le 12000000 ]; do echo $counter; counter=$(( $counter + 1 )); done"]
#cloud-config
power_state:
mode: poweroff
message: Bye Bye
condition: True
But, my virtual machine gets started within 1 minute. Even, if I enter shutdown/poweroff command in ubuntu Virtual Machine terminal, it is still in Running state. I am trying in IBM Cloud.
Later, I found that "cloud init gets executed after instance starts". This is mentioned in one of the website:
Cloud-init is the service that is installed inside the instance and cloud-config are a set of scripts that are executed as soon as the instance is started. Cloud-config is the language of the scripts that cloud-init knows to execute.
Does anybody has any idea how to achieve this ?