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 have a CentOS 5.2 box running my production web server (Apache 2 + Mongrel_cluster) for a Ruby on Rails project. The machine is hosted by GoDaddy.com and is a "virtual private server". The system periodically reboots on its own (maybe once every 6 months). I have two questions:

  1. How can I determine why my machine rebooted?
  2. Is there a good way to automagically notify me (i.e. via e-mail) when the system reboots?
share|improve this question

3 Answers 3

up vote 4 down vote accepted
  1. Check /var/log/messages for the suspected time it rebooted
  2. Put a one-liner in /etc/rc.local like:

    /bin/date +%F_%T | /bin/mail -s "myhost was rebooted" me@example.com

Cheers

share|improve this answer
3  
what's the point in date since it will be already in email's headers? –  alexus Jul 29 '09 at 4:02
3  
@alexus: Do you really want to dig the headers out and read them to get the date, or do you want to simply see it in the message title? –  Avery Payne Jul 29 '09 at 4:31
3  
no i wouldn't want to dig any headers, most modern clients shows you date so no need to dig out anything... –  alexus Jul 29 '09 at 16:08
    
@alexus many modern clients show the received date, not the sent date, to protect against malicious or malformed date headers –  Sparr Jan 20 '11 at 2:14
    
sadly I've got this same problem and /var/log/messages contains no useful information. Nothing is logged for 5-30 minutes prior to syslog registering a restart –  Sparr Jan 20 '11 at 2:23

put following in cron

@reboot echo "rebooted" | mail root

there is also some other services out there that monitors your server, i'm pretty sure even godaddy should do it, not to mention they should look into that if its their server

share|improve this answer
    
For some reason anything as "@reboot" in my crontab doesn't run @ boot. However, adding it to /etc/rc.local seems to do the trick. Thanks for the ideas! –  Pete Jul 29 '09 at 4:09
    
Also, what are some of the "other services out there that monitors [my] server"? –  Pete Jul 29 '09 at 4:34
1  
@Pete: other services that monitor: try servermojo.com or if you prefer local monitoring, try nagios. –  gbjbaanb Jul 29 '09 at 8:49
    
i do monitoring myself and I provide monitoring for others, but i'm pretty sure there are others provides that does that as well. –  alexus Jul 29 '09 at 16:09

As previously mentioned by Jason, check /var/log/messages (and/or /var/log/warn if you have it). Seeing as the box is owned by GoDaddy, call them and ask what's up with reboots. It could anything from a hardware glitch they don't know about (or are ignoring) to a reboot for a new kernel. Either way, they should now when/why it happens.

share|improve this answer

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.