What I Learned Today
I am not sure what has gotten into me, but I decided to set up monit on my MacBook Pro. Monit's used for monitoring Unix systems, especially servers and the processes on those servers. I read a presentation on Monit (PDF) that showed me how to monitor files for changes and then execute commands based off that, like reloading Apache whenever you edit your Apache configuration file. And then I thought, "Why don't I do this on my laptop?"
There's only a few steps. The first is getting monit installed. It's not hard, and the tarball; ./configure; make; make install biz should work for you. If you like Homebrew like I like Homebrew, you can grab a recipe from this here commit.
Next, configure monit. I put my monit configuration file in /usr/local/etc/monitrc. I'll show it at the bottom of this post.
My major issue was with mail delivery. If you have a SMTP server you want to use, you're set. If you want to use your OS X box as a mail server, you've got to reconfigure Postfix. By default, it only runs when files are put in /var/spool/postfix/maildrop. Here's my configuration from /System/Library/LaunchDaemons/org.postfix.master.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AbandonProcessGroup</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.postfix.master</string>
<key>OnDemand</key>
<false/>
<key>Program</key>
<string>/usr/libexec/postfix/master</string>
<key>ProgramArguments</key>
<array>
<string>master</string>
</array>
<key>QueueDirectories</key>
<array/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Learn more about launchd so I won't have to post a giant slab of XML again.
Once I got mail delivery going (you might need to edit /etc/aliases and then run sudo postalias /etc/aliases; sudo postfix reload) and mutt installed to check my mail, which I leave as an exercise to the reader, I was set. I dropped the following configuration in /usr/local/etc/monitrc:
set daemon 120
set logfile syslog facility log_daemon
set alert cnixon@localhost
set mail-format { from: monit@moro.local }
set mailserver localhost
set httpd port 2812 and use address localhost
allow localhost # Allow localhost to connect
check directory vhosts path /etc/apache2/passenger_pane_vhosts
if changed timestamp
then exec "/usr/sbin/apachectl graceful"
check directory apache_conf path /etc/apache2/other
if changed timestamp
then exec "/usr/sbin/apachectl graceful"
check file monitrc path /usr/local/etc/monitrc
if changed timestamp
then exec "/usr/local/bin/monit reload"
check device MacintoshHD with path /
if space usage > 90%
then exec "/usr/local/bin/growlnotify -m \
'Your harddrive is getting full' 'MONIT SAY'"
Check out the PDF presentation above, or the Monit documentation if a line doesn't make sense. The summary:
When I add or remove any files from /etc/apache2/passenger_pane_vhosts or /etc/apache2/other, Apache gets reloaded. I'd like it to do this whenever a file is changed in either one, but monit doesn't easily support file globs. Maybe I should write a script to write my monit conf.
When I change
monitrc, monit reloads it.If my hard drive starts to get full, Growl tells me about it.
Published: