Adventure Log

17 Sep 2009 » Permalink » View Comments

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.

17 Sep 2009 » Permalink

Check out my post on MongoDB and MongoMapper at Viget Extend today.

16 Sep 2009 » Permalink » View Comments

I continued adding stuff to my thor bandolier today, including some sweet meta-tasks to help deal with thor. Check them out at my git repo for my thor tasks. One thing to especially look at is provision.thor. I had no idea until today that you can make a .thor directory with a main.thor file inside to drive it.

My zsh completion for thor quest continues. It is still breaking me - three hours already, and not satisfied - but I'm making progress. Here's the latest:

#compdef thor

# List of commands built into thor.
_thor_commands() {
  _values "Thor" "list" "install" "uninstall" "help" "installed" "update"
}

# Get list of all thor tasks added.
_thor_tasks() {
  compadd `thor list | grep -vP '^[\#\-]|^\s*$' | 
    sed -e '1d' -e 's/[^a-zA-Z0-9_\-\:].*$//' | grep -v '^\n$'`
}

# Normally, show all of the above.
if (( CURRENT == 2 )); then
  _thor_commands
  _thor_tasks
else
  # If we've typed 'thor install', let us look for a normal file.
  if [[ $words[2] == install ]] ; then
    _files
  # If we've typed 'thor help', just show us the built in thor commands.
  elif [[ $words[2] == help ]] ; then
    _thor_commands
  fi
fi

15 Sep 2009 » Permalink » View Comments

I spent some time this afternoon thinking about automation with Ruby. Even though I used to use it a lot, I've fallen off on using Thor, mainly because of API changes in Thor, and my move to zsh. I ported my bash completion script for thor to zsh, and it was way easier than bash:

_thor() {
  compadd `thor list | grep -vP '^[\#\-]|^\s*$' | 
    sed -e '1d' -e 's/[^a-zA-Z0-9_\-\:].*$//'`
}

compdef _thor thor

11 Sep 2009 » Permalink

I've been using Ruby 1.9.1 as my primary Ruby on my box for a week now, and no real problems. The only major issue I've had was that the Mongrel gem wouldn't install. I found a patched version of Mongrel for Ruby 1.9 this morning, and am in business now.

10 Sep 2009 » Permalink

This weekend, I posted about my love affair with Homebrew, a new package management system for nerds who use OS X. I improved the API a lot today, which lets me make formulas that look like this:

class Zsh < StandardUnixFormula
  url 'http://downloads.sourceforge.net/project/zsh/zsh-dev/4.3.10/zsh-4.3.10.tar.gz'
  homepage 'http://www.zsh.org/'
  md5 '031efc8c8efb9778ffa8afbcd75f0152'
  skip_clean true
end

Grab the commit or clone my branch on GitHub.

28 Jul 2009 » Permalink

I pulled off a feat in the last few days: I upgraded a Radiant 0.6.9 site to 0.8.0. A lot of the architecture has changed between those revisions. There's not a clear upgrade path, but lessons I learned:

  • Migrate each extension one at a time. If possible, get a new version of the extension.
  • Not all extensions are Rails 2.3 compatible yet, so make sure you change require_dependency 'application' in all of them to require_dependency 'application_controller'.
  • Don't forget to run rake radiant:update. I did, and it bit me hard.
  • There's one migration change between the two that isn't a new migration, but made in an old one, so you'll have to do it yourself: add a schema_version integer column with a default of 1 to extension_meta.

The other thing I've been learning isn't technical. It's the Spanish language. So far, I'm enjoying it. It will be quite a while before I'm proficient, but I'm considering attending Conferencia Rails as a reward if I work hard at it.