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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With