0
votes

I am looking for a way to execute a script at instance launch in Google cloud platform similar to user data in AWS. I check 'Startup script' but it is executed at every boot. is there any way to achieve it?

1

1 Answers

1
votes

Yes, accordingly to the documentation startup script runs on each boot and there's no option available to change this behavior:

Compute Engine lets you create and run your own startup scripts on your virtual machine (VM) instances to perform automated tasks every time your instance boots up. Startup scripts can perform actions such as installing software, performing updates, turning on services, and any other tasks defined in the script.

To solve this issue you can use this workaround:

  1. Set up a flag, such as a file on the disk, when your startup script runs first time.
  2. Check existence of this flag in your startup script and exit without any action if the flag exists.