AWS EC2 instance automatically restarts

0

Hi,
On AWS EC2 Ubuntu 20.04 and earlier, I was able to set up a crontab to shut down the instance at night.
0 5 * * * /sbin/shutdown -h now

On Ubuntu 22.04 the server automatically restarts again. Could this be modified so the shutdown command works correctly?

Thanks.

sdarwin
asked a year ago363 views
2 Answers
1
Accepted Answer

The instance may have Auto Recovery set to true. The link shows how to disable this.

I've been able to recreate this behavior on both Ubuntu 20 and 22. Though, I can not recreate it consistently. Seems to happen more often on t2.small vs t3.small. Also, seems to happen more often the first time I issue the sudo shutdown -h now command. But after that first failure, it works as expected. All of this was independent of the Auto Recovery setting. Recommendation at this point is to use the stop-instances API for consistent behavior. See: Instance Scheduler

profile pictureAWS
EXPERT
kentrad
answered a year ago
  • Although this idea "The behavior recently changed so mostly likely connected the age of the instance" sounds very plausible and more believable, I have just retested another time, and the results are as follows. A new ubuntu 20 instance can be shutdown from the command line. A new ubuntu 22 instance gets auto restarted.

  • Interesting. I'll give it a try today.

0

@kentrad thanks!
There is still some mystery to it, because I re-verified that on Ubuntu 20 auto recovery didn't need to be adjusted. Not sure what's possible and what's not possible but the ideal behavior would be that a manual shutdown by issuing the shutdown command would stop the instance, and a crash would auto recover. However, if aws can't distinguish the difference between those two conditions, then maybe it has no choice but to reboot both of them.

sdarwin
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions