-1

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 ?

Malar Kandasamy
  • 839
  • 2
  • 10
  • 17
  • You're doing the check on the outside of the VM? As in, you check the state of the VM on the outside and if it's not running after ten minutes, execute something on the outside of that VM? If so, does having a fatal bootloading count? – wxz Apr 22 '21 at 03:05
  • it seems that you does't clear on what you need. "INSTANCE STARTED" in your term is an status from Hypervisor. When virtual bios, even before guest os starts, the INSTANCE is already in STARTED state. What you trying to achieve - is to slow down the Hypervisor state change from provisioning to instance started. It is not related to Ubuntu or anything, in your case this is the question to IBM Cloud – Reishin Dec 15 '22 at 18:17

1 Answers1

0

Assuming that the Ubuntu version is new enough, you might be able to follow the directions of this stack overflow answers:

How to ensure that there is a delay before a service is started in systemd?

Ricardo
  • 472
  • 3
  • 6
  • Some command during instance boot to slow the instance start. I want to delay the instance start. How to achieve that ? Service runs after instance starts. Is there any service that triggers/part of instance start ? – Malar Kandasamy Apr 22 '21 at 04:59