在Google可抢占实例上被抢占时如何保存状态? [英] How to save state when preempted on a Google preemptible instance?

查看:153
本文介绍了在Google可抢占实例上被抢占时如何保存状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够在基于Centos的Google Compute实例首次收到抢占信号时保存其状态. 文档非常清楚地表明"ACPI G2 Soft Off"信号是在抢先关机前30秒发送.不幸的是,Google没有提供任何示例来演示如何捕获此信号,我还没有找到捕获它的方法.

我最初的尝试都集中在使用acpid守护程序的ACPI接口上.使用它,我能够毫无问题地捕获关机(按钮/电源)事件.但是无论我尝试捕获什么事件(按钮,电源,睡眠),我都无法捕获向G2状态的状态转换,我认为这正是我要寻找的.

有人在Centos(或任何Linux)环境中成功地捕获了抢占信号吗?

解决方案

您可能想使用关闭脚本:

创建并运行关闭脚本,这些脚本可让您尽最大努力在实例终止或重新启动之前立即执行命令.如果您依靠自动化脚本来启动和关闭实例,从而使实例有时间清理或执行任务(例如导出日志或与其他系统同步),这将非常有用.

如果您具有正在自动缩放的托管实例组,则关闭脚本可能会很有用,因为如果由于自动缩放而关闭了实例,则关闭脚本会在终止实例之前执行您定义的所有操作.例如,您的关闭脚本可能会复制已处理的数据或备份任何日志.

关机脚本的功能与启动脚本非常相似;启动脚本的许多文档也适用于关机脚本.

但是,由于您的工作时间有限,请考虑使用永久性外部存储系统,这些系统在您的实例被抢占时不会被删除,例如, Google Cloud Bigtable Google Cloud Datastore 或其他.

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?

解决方案

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.

这篇关于在Google可抢占实例上被抢占时如何保存状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆