Google Cloud Platform: Properly Shutting Down Preemptible Linux VM Instances

Properly Shutting Down Preemptible Linux VM Instances

Question

You have created several pre-emptible Linux virtual machine instances using Google Compute Engine.

You want to properly shut down your application before the virtual machines are preempted.

What should you do?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

C.

A startup script, or a shutdown script, is specified through the metadata server, using startup script metadata keys.

https://cloud.google.com/compute/docs/startupscript

When using pre-emptible instances in Google Compute Engine, it's important to properly shut down your application before the instances are preempted. This helps ensure that any data or processes running on the instances are not lost or corrupted. To do this, you can create a shutdown script that will run when the instance is being shut down.

Option A, creating a shutdown script named k99.shutdown in the /etc/rc.6.d/ directory, is not recommended. This directory is used for system startup and shutdown scripts, and creating a custom script here could interfere with system functionality.

Option B, creating a shutdown script registered as a xinetd service in Linux and configuring a Stackdriver endpoint check to call the service, is also not recommended. While this approach would allow you to trigger the shutdown script remotely, it's more complex than necessary for this scenario.

Option C, creating a shutdown script and using it as the value for a new metadata entry with the key shutdown-script in the Cloud Platform Console when you create the new virtual machine instance, is a viable option. This would allow you to specify a custom shutdown script to run when the instance is being shut down. To do this, you would create a shutdown script and upload it to a Cloud Storage bucket. Then, when creating a new instance in the Cloud Platform Console, you would specify the URL for the shutdown script as the value for the shutdown-script metadata key.

Option D, creating a shutdown script registered as a xinetd service in Linux and using the gcloud compute instances add-metadata command to specify the service URL as the value for a new metadata entry with the key shutdown-script-url, is also a viable option. This would allow you to trigger the shutdown script remotely using the gcloud command-line tool. To do this, you would create a shutdown script and register it as a xinetd service. Then, you would use the gcloud compute instances add-metadata command to specify the URL for the xinetd service as the value for the shutdown-script-url metadata key.

Overall, both options C and D are viable approaches for properly shutting down your application before pre-emptible instances are preempted. The choice between them will depend on your specific needs and preferences.