Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm running ec2 instance with ubuntu server and sometimes it seems to be shut down. Is it possible to send an email notification, if server switches to runlevel 0? And how?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Probably a better alternative that will handle external shutdown cases (server crash, service disruption, kernel panic, etc) is to use Amazon's CloudWatch and Simple Notification Services to send you Alarms.

http://aws.typepad.com/aws/2010/12/amazon-cloudwatch-alarms.html

Just set your thresholds (in this case, probably INSUFFICIENT_DATA) and where you want the alert to go (in your case, probably email) and let Amazon handle the rest.

share|improve this answer

For linux boxes in general, find the default runlevel by doing a

grep id /etc/inittab

and looking at the second of the colon-separated fields. It's usually 3 or 5, with the former more common in servers.

Assuming it's 3, look in /etc/rc3.d at the scripts which start Knn, where nn is a two-digit number. These are normally run in increasing numerical order when the server leaves that runlevel.

You will want to write something short and sweet and put it in there for early running, say K01shutmail. The server will be shutting down your MTA very shortly thereafter, so you'll only have a short time to get this mail sent; don't make your script over-complex.

This will still only help you if the server shuts down gracefully, and if you're finding it shut down for no clear reason, that may not be so. If the availability of your box is important to you, I would personally recommend putting a small nagios installation on a cheap shared-hosting server elsewhere, and have that monitor your ec2 box.

share|improve this answer
    
Thank you, it seems to be helpful info –  Shaman Nov 26 '10 at 13:21

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.