大网数据广告活动
服务器运维问答

Automatically shut down server on inactivity (SSH)?

· 52CE 我爱测

I have a server hosted on EC2 . The server is built on the Linux AMI , based on CentOS. It is dedicated to a client project, and I connect via SSH. Sometimes, I forget to shut down the server when unused, therefore generating unn…

问题原文

原帖链接 · feklee · CC BY-SA 3.0

I have a server hosted on EC2. The server is built on the Linux AMI, based on CentOS. It is dedicated to a client project, and I connect via SSH. Sometimes, I forget to shut down the server when unused, therefore generating unnecessary costs.

How do I make the server shut down automatically on inactivity, for example after 30 min without an SSH connection?

Naturally, I am looking for the simplest solution. A check every hour or so would also be OK, just something that works reliably.

已采纳解答

原帖链接 · Steffen Opel · CC BY-SA 3.0

As of January 2013 Amazon CloudWatch provides an option to Use Amazon CloudWatch to Detect and Shut Down Unused Amazon EC2 Instances, see the introductory blog post Amazon CloudWatch - Alarm Actions for details on this functionality:

Today we are giving you the ability to stop or terminate your EC2 instances when a CloudWatch alarm is triggered. You can use this as a failsafe (detect an abnormal condition and then act) or as part of your application's processing logic (await an expected condition and then act). [emphasis mine]

Your use case is listed in section Failsafe Ideas specifically:

If you (or your developers) are forgetful, you can detect unused EC2 instances and shut them down. You could do this by detecting a very low load average for an extended period of time. This type of failsafe could be used to reduce your AWS bill by making sure that you are not paying for resources you're not actually using.

As outlined, this depends on being able to heuristically detect the appropriate condition triggering the alarm and stopping the instance - you might take it to the next level by means of Publishing Custom Metrics to CloudWatch based on the logged in SSH user count, idle time or else and gain more control/precision for the desired detection and shutdown process in turn.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-03-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。