0

I beleived that Google Cloud Platform preemptive instances were restarted automaticaly when the engine releases the ressource but I was wrong.

Once preempted the instance seems to need a manual restart.

Is there a way to restart the instance automaticaly after preemption ??

Thank you.

1 Answers1

0

You can instance status periodically and restart it if it was terminated. Assuming instance name instance1 and period 5 minutes it will be something like this:

while true 
do
    status=`gcloud compute instances list --filter name=instance1 | tail -1 | awk '{print $NF}'`
    [[ $status == TERMINATED ]] && gcloud compute instances start instance1
    sleep 300
done
Yuri Ginsburg
  • 2,302
  • 2
  • 13
  • 16