Skip to content

Instantly share code, notes, and snippets.

@syoyo
Last active December 2, 2017 20:56
Show Gist options
  • Save syoyo/e29580d6f952d30e8042 to your computer and use it in GitHub Desktop.
Save syoyo/e29580d6f952d30e8042 to your computer and use it in GitHub Desktop.
GCE instance explicit termination
gcloud compute instances create ${GCE_MASTER_INSTANCE_NAME} ...
# wait instance boot up
# fixme: there should be much better way
sleep 30
# shutdown after 60 min
# must add -f flag(background execution)
gcloud compute ssh ${GCE_MASTER_INSTANCE_NAME} --zone ${GCE_ZONE} --ssh-flag="-f" --command="sudo /sbin/shutdown -h -P +60"
@syoyo
Copy link
Author

syoyo commented Sep 22, 2015

Using metadata startup-script looks much better

gcloud compute instances create ${GCE_MASTER_INSTANCE_NAME}
--quiet
--preemptible
--metadata startup-script="nohup sudo /sbin/shutdown -h -P +60 &"
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment