Tom Offermann
Tom Offermann

Reputation: 1421

When is an EC2 instance in "shutting down" state killed automatically?

According to the docs found at the Amazon EC2 Instance FAQ:

"Instances in the “shutting down” state for longer than usual will eventually be cleaned up by automated processes within the Amazon EC2 service. "

Does anyone know how long "longer than usual" is? How long can an instance be in the "shutting down" state before it is killed automatically?

I call a backup script from an init.d shutdown script, but when it tries to zip up and copy a large directory (500 MB) to S3, it seems like the EC2 instance shuts down before the backup completes. (I never experience this problem when backing up small directories during shutdown.)

Is it possible that my EC2 instance is getting killed automatically because it is staying in the "shutting down" state too long? How long can I safely stay in "shutting down" state?

Upvotes: 4

Views: 6221

Answers (2)

Eric Hammond
Eric Hammond

Reputation: 22407

When you stop or terminate an EC2 instance, Amazon sends a soft shutdown request to the operating system to let it wrap up in a clean, safe manner. If the system does not indicate it is powering down within a short time (minutes) then Amazon effectively pulls the power plug forcing a hard shutdown.

I am not aware of any commitment from Amazon about how long this soft shutdown grace period is, so I would recommend you not assume or rely on having a specific minimum. Even if Amazon gives you 10 minutes today for one instance, they could easily reduce this to 3 minutes tomorrow when, say, they have a large demand for new instances.

If you need to do important wrap up before an instance shuts down, then send the instance a signal (web request or ssh command), wait for it to complete its task, then initiate the EC2 shutdown.

If you are using, say, spot instances where the instance can be shut down at any point by Amazon, then save your work frequently so that not much of it will be lost if the instance gets terminated suddenly.

Answer copied from my ServerFault answer to Is there a maximum shutdown for instances in Amazon EC2?

Upvotes: 6

Suman
Suman

Reputation: 9561

Is this a controlled shut down event? Are you shutting it down from within the EC2 instance itself or outside the instance?

In either case, once you issue a shutdown signal to an EC2 instance, its the same as issuing a "shutdown -h now" command - you really don't have much time to do much before the system goes down.

If this is a controlled shutdown, I recommend finding another way to run that script outside of an init.d shutdown script.

Upvotes: 0

Related Questions