How to save state when preempted on a Google preemptible instance?
Asked Answered
P

1

1

I need to be able to save the state of a Centos-based Google Compute instance when it first receives a preemption signal. The documentation very clearly indicates that a "ACPI G2 Soft Off" signal is sent 30 seconds before a preemptible shutdown. Unfortunately, Google has given no examples to demonstrate how to capture this signal and I have not yet found a way to capture it.

My initial attempts have all been focused around the ACPI Interface using the acpid daemon. Using it, I have been able to capture the shutdown (button/power) event without any problems. But no matter what event I try to capture (button, power, sleep) I have not been able to capture the state transition to the G2 state, which I presume is what I am looking for.

Has anyone successfully managed to capture the preemption signal in a Centos (or any Linux) environment?

Pease answered 5/10, 2015 at 12:52 Comment(0)
C
2

You may want to use shutdown scripts for this:

Create and run shutdown scripts that allow you to execute commands right before an instance is terminated or restarted, on a best-effort basis. This is useful if you rely on automated scripts to start up and shut down instances, allowing your instances time to clean up or perform tasks, such as exporting logs, or syncing with other systems.

If you have a managed instance group that is being autoscaled, shutdown scripts can be useful because if an instance is shut down due to autoscaling, the shutdown script performs any actions you define before the instance is terminated. For example, your shutdown script might copy processed data or back up any logs.

Shutdown scripts function very similarly to startup scripts; much of the documentation for startup scripts also applies for shutdown scripts.

However, since you have limited time to do the work, consider using persistent external storage systems which won't be deleted when your instance is preempted, e.g., Google Cloud Storage, Google Cloud Bigtable, Google Cloud Datastore, or others.

Chronology answered 5/10, 2015 at 16:21 Comment(2)
Thanks Misha; I will give the shutdown script a try. But wouldn't it be better to capture the initial G2 state change? If so, is there not a way to use this earlier information?Pease
@NigelRMurray — sorry, don't know if it's possible to capture the G2 state change, or how to do that.Chronology

© 2022 - 2024 — McMap. All rights reserved.