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!


Leopard 10.5 Log Rotate

I recently had an issue where I have a Zope instance installed from source and found that the Z2.log and event.log files were 17GB and 30GB respectively.

Poking around the google, I found this reference to newsyslog.conf: http://www.wrightthisway.com/Articles/000437.html

I added this entry just for testing to see if this would work as advertised.

#logfilename                              [owner:group]   mode  count     size       when     flags

/Path/to/Zope/log/event.log  owner:group       644       5           5000       *             J

This entry tells newsyslogd to rotate the event.log file when it reaches 5000kB (5MB) and create the new file with specified owner:group permissions.  In addition keep 5 copies of the log file and compress them with bzip2 compression.

You can rotate your logs at the command line with:  sudo newsyslog -F

UPDATE:  With this solution, the Zope service doesn’t get restarted so it doesn’t continue to write to the newly created log file.

There is an option to give  PID but I have a suspicion that the process will be hung up and not restarted.

I found this http://httpd.apache.org/docs/1.3/logs.html#rotation

where I can use the rotatelogs apache command which is a piped log that allows log rotation without having to restart the service.

In order to use the rotatelogs command you would add an entry like below in your httpd.conf file.  I would change the entries to be all ErrorLog entries and only have the combined entries for Apache combined access logs.  The 5M is once the log file is 5M and the -420 is an offset for Pacific standard time.

CustomLog ‘|/usr/sbin/rotatelogs “/usr/local/apache2/logs/access_log” 5M -420’ “%h %l %u %t \”%r\” %>s %b”
ErrorLog ‘|/usr/sbin/rotatelogs “/usr/local/apache2/logs/error_log” 5M -420’

Leopard diskutil Software RAID

Here is a helpful link: http://reviews.cnet.com/8301-13727_7-10330310-263.html

I recently had a degraded software RAID on one of my Leopard servers.  In trying to rebuild the disk through Disk Utility, I was getting a unrecognized file system error.  I found this post: http://discussions.apple.com/thread.jspa?threadID=1212964&tstart=0

I followed the following steps:

#Checked the RAID status
root# diskutil checkRAID
Name: Server_HD
Unique ID: 7E31E20E-F53D-4D76-AD37-139C4E1440AB
Type: Mirror
Status: Degraded
Size: 1000070610944 B
Device Node: disk2
Apple RAID Version: 2
Device Node UUID Status
0 disk1s3 BAC72F86-B05F-4B0F-97D3-58A6207E7DFA Failed
1 disk0s3 2BFB55BB-EFF9-438C-A1F9-A8ED7A93D385 Online
#Told it to resync
root# diskutil repairMirror disk2 disk1s3
Note: Syncing data between mirror partitions can take a very long time.
Note: The mirror should now be repairing itself. You can check its status using ‘diskutil listRAID’.
temp:~ root# diskutil listRAID
Name: Server_HD
Unique ID: 7E31E20E-F53D-4D76-AD37-139C4E1440AB
Type: Mirror
Status: Degraded
Size: 1000070610944 B
Device Node: disk2
Apple RAID Version: 2
Device Node UUID Status
0 disk1s3 9D955C85-7EC0-4E92-848A-62D9F7C12EED 0% (Rebuilding)
1 disk0s3 2BFB55BB-EFF9-438C-A1F9-A8ED7A93D385 Online

When I ran the diskutil listRAID command, there was still a failed message on the disk. I had recently installed SmartReporter and thought that might be causing an issue.  I had installed it on two other servers with no issues. So I stopped SmartReporter and the repairMirror command worked and the RAID started rebuilding.

I found this second post to use the diskutil checkRAID, diskutil addToRAID and diskutil removeFromRAID commands to rebuild the RAID as well. http://blog.smalldog.com/article/1007/software-raid-in-os-x-leopard.

apachectl error OS X Leopard 10.5.x

I ran into an apachectl -t error that said a library variable _u_tolower_3_4 could not be found.  Then I found this post from a Google search:http://www.thoughtspark.org/node/19

My httpd -t configuration check was coming back with no errors so I commented the 2 lines in the /usr/sbin/envvars file and my apachectl -t worked just fine with no errors.

My PHP environment was installed using the Entropy package provided here: http://www.entropy.ch/software/MacOSX/php