OS X Leopard Rotate Logs and Restart Zope

I recently ran into an issue where our Zope process was crashing.  We have 4 Zope processes installed, 3 are load balanced with Zeo and the forth is for images files.

I created a script that would check the size of the log files for each instance and if the size of the log files was bigger than 1GB to rotate the logs and restart that particular Zope instance. The name of my script was logrotate.sh.

Now I wanted this script called at a specified day of the week and time so I couldn’t just add it to /etc/periodic/weekly, well I could and then change the time that the weekly scripts run but I didn’t want to change that system wide.  If I wanted to change it though you would edit /System/Library/LaunchDaemons/com.apple.periodic-weekly.plist and edit the Hour, Minute, and Weekday integers as appropriate.

So I created my own plist and added it to /System/Library/LaunchAgents/edu.ucla.zoperestart.plist

Here’s what my plist looks like:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0dtd”&gt;
<plist version=”1.0″>

Now I had to load the plist so that launchctl was aware of it and would read the xml file and run it at the appropriate time.

launchctl load /System/Library/LaunchAgents/edu.ucla.zoperestart.plist

Verify that the plist is loaded:

launchctl list

I purposely set the date and time to 15 minutes in the future just to test that launchd ran my script.  Now it’s working great!


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s