Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differentiating between preemption and manual shutdown in GCE

Is it possible to capture the shutdown trigger event type somehow from inside a GCE instance?

For example in a shutdown script I would like to have different actions happening based on what triggered the shutdown: did the machine get preempted or did someone manually stop it?

like image 892
danthelion Avatar asked Oct 17 '22 21:10

danthelion


1 Answers

I believe the best way to capture the shutdown trigger is by checking the metadata server for the preempted value in the instance's default instance metadata.

A curl within the instance to find out the value for preempted can be used to determine whether the instance was preempted by Compute Engine or not. If the value is TRUE, it was preempted by Compute Engine and if it is FALSE, it was not.

curl "http://metadata.google.internal/computeMetadata/v1/instance/preempted" -H "Metadata-Flavor: Google"

That said, you can always check this document for more information on determining if an instance was preempted.

like image 125
Taher Avatar answered Oct 20 '22 16:10

Taher