Instantly restart a server or workstation each day

Oct 17, '05 05:43:00AM

Contributed by: TigerKR

Among other things, I administer two identical servers located in different locations on different LANs. They're running Mac OS X 10.4.2 client w/all updates and they run the services: ipfw, nat, dhcp, dns, and ssh. Unfortunately there seems to be a bug in Tiger which causes my servers to freeze frequently. The servers don't automatically login (all of their services are daemons, and don't require an user account). I tried changing RAM, repairing permissions, running Disk Warrior, Drive Genius, zapping the PRAM, etc. I am fairly confident that its not a hardware problem, because it's occurring on two separate but identically-configured servers (on two different LANs, from two different ISPs).

It has been suggested that lookupd is the culprit, and the recommended solution is the third-party unlockupd daemon. However, even running unlockupd, my servers freeze frequently. I figured that I'd try a hardware solution called Kick-Off! to restart the computers when they freeze. However, even using Kick-Off!, my servers freeze frequently.

I did notice that, most of the time, the servers last at least 24 hours between freezes, so I decided to implement a once a day, automatic restart. But these servers are very important, so I want them to have as little downtime as possible. So I choose the time of day with the least traffic to implement this daily restart.

I did not want to use the Energy Saver Preference Pane of Mac OS X to shut down then start up the computer, because I can't have the machines down for more than a minute at a time -- so I can't separate the shutdown and startup times by more than a minute. Also, I can't have the machines miss their startup time because they're still shutting down a lot of processes (so I can't separate the shutdown and startup times by less than a minute). So here's how I decided to proceed. I decided to simply add a line to the /etc/crontab file:

$ sudo nano -w /etc/crontab
Password:
# The periodic and atrun jobs have moved to launchd jobs
# See /System/Library/LaunchDaemons
#
# minute        hour    mday    month   wday    who     command
30    6    *    *    *    root    /sbin/shutdown -r now
Control-X y
It is important to note that the spaces shown between the items above (in the 30... row) are tabs. Use Control-X to exit nano, and hit y to tell nano that you want to save your changes. That tells the computers to have the root user (root account does not need to be enabled) execute the instant restart command everyday at 6:30 AM.

I understand that using the crontab is being depreciated, however, for the life of me, I could not get a launchd LaunchDaemon to execute at the time that I specified. I did use plutil to make sure the syntax was correct, I did set the owner and permissions properly, and I did remember to use launchctl to load the file, etc. I know the command worked because I could sudo launchctl load /Library/LaunchDaemon/daily-restart.plist, and then manually do sudo launchctl start daily-restart, and it would restart the comp immediately. However, it never worked at the time that I specified in the plist file. Oh well.

Comments (22)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20051013041404296