Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terminate google cloud compute engine instance with shell/bash script

I am using google cloud compute engine for some computational intense tasks (32 parallel processes). My tasks sometimes finished in mid night, and I am wondering is there a way to stop the instance once all my processes stop? I prefer to make a shell script to monitor all my processes and stop the instance when everything is finished.

halt or shutdown or poweroff does not works for me, as my command only submit jobs. The command finished immediately while all processes (computing tasks) kept running on the backend. If I put halt or shutdown at the end of my command line, the instance simply shut down as I entered the command

like image 626
SimonInNYC Avatar asked Jul 20 '16 00:07

SimonInNYC


People also ask

How do I exit Google Cloud Shell?

You need to press the letter q to "quit" from that. You can press "h" for help.


2 Answers

Take a look at How to automatically exit/stop the running instance.

To summarize, you can simply run halt or shutdown -h now. Once the operating system halts the instance will terminate and you will no longer be charged.

Alternatively if you've started the instance with the appropriate permissions/scope you could issue the gcloud compute instances stop command:

https://cloud.google.com/sdk/gcloud/reference/compute/instances/stop

like image 66
Ramesh Dharan Avatar answered Sep 22 '22 09:09

Ramesh Dharan


I typed:

gcloud compute instances stop [virtual-machine-instance]

Therafter, you specify the zone [zone] to confirm terminating instance

like image 29
Raul Maldonado Avatar answered Sep 22 '22 09:09

Raul Maldonado