4

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?
Pete
  • 345
  • 1
  • 4
  • 10

3 Answers3

5
  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

HTTP500
  • 4,827
  • 4
  • 22
  • 31
  • 3
    what's the point in date since it will be already in email's headers? – alexus Jul 29 '09 at 04: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 04: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 02: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 02:23
1

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

alexus
  • 12,342
  • 27
  • 115
  • 173
  • 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 04:09
  • Also, what are some of the "other services out there that monitors [my] server"? – Pete Jul 29 '09 at 04:34
  • 1
    @Pete: other services that monitor: try http://www.servermojo.com/ or if you prefer local monitoring, try nagios. – gbjbaanb Jul 29 '09 at 08: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
1

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.

David
  • 3,519
  • 21
  • 17