Search code examples
google-compute-enginestartupscript

Detect google compute instance startup script finished?


In Google Compute Engine, when starting a virtual machine, an operation is created. When the operation is done, the virtual machine is ready (or the operation could have a failed status). However, my startup script (specified via startup-script-url) is still running after a successful insert operation.

Is there a way to detect using the compute api?

I'm using the googleapis node library which is basically a wrapper around the official Compute Api (https://developers.google.com/apis-explorer/#p/compute/v1/).

When I'm doing this manually, I just keep an eye on the serial console.


Solution

  • Not sure if this would work, but you could let your startup script add a tag to its host once it's done: https://cloud.google.com/sdk/gcloud/reference/compute/instances/add-tags

    Then you could poll calls to describe: https://cloud.google.com/sdk/gcloud/reference/compute/instances/describe

    Once you see the tag added there your script should be done.