Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've put together a simple "deadman switch" using upstart to automatically shutdown my EC2 instances after a period of time. I'm doing this to avoid the dreaded Monday morning blues when you realized you've left a instance up and running all weekend (and yes, I could use cloud watch but I was hoping for a very straightforward and easy solution).

My question is that will I run afoul with any problems if my upstart script is simply:

sleep +55m
shutdown -h now

I'm worried that when the shutdown changes the run levels that it could have some negative consequences when it gets to the upstart process that is running the shutdown itself.

Thanks

share|improve this question

2 Answers 2

shutdown -h now is a non-blocking command, so there is no issue as the job exits right after it has issued shutdown request to the kernel.

share|improve this answer

Random ideas if you run into problems with your current approach:

  1. Toss the commands in the background:

    (sleep +55m; shutdown -h now) &
    
  2. Tell shutdown to schedule it for 55 minutes in the future and toss it in the background:

    shutdown -h +55 &
    
  3. Use "at" to schedule the action:

    echo "shutdown -h now" | at now +55min
    

NOTE: For an EBS boot EC2 instance, the default "shutdown" action is to simply "stop" the instance. If you want to "terminate" the instance, you will need to set the instance-initiated-shutdown-behavior to "terminate".

On the ec2-run-instances command line, this can be done with the option:

--instance-initiated-shutdown-behavior terminate

The AWS console has similar options.

share|improve this answer
    
Thanks for the suggestions. I had originally tried the "shutdown -h +55" which works great until you want to run an "shutdown -h now" outside of the upstart process. When you do this you get the expected "shutdown: Another shutdown is already running" message and have to stop the upstart process and re-issue again. Worse when doing the "-h +55" it seems that if you terminate the EC2 instance using the API it just hangs for 120 seconds till AWS just kills off the instance. –  JoeS Jun 14 '13 at 23:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.