Fixing “MAC address could not be autodected” error from UUIDTools, Phusion Passenger and Ruby Enterprise Edition

I’m using the UUIDTools 1.0.3 gem in a Rails 2.1 application to generate globally unique IDs. After migrating the site to run under Phusion Passenger and Ruby Enterprise Edition I began encountering the following error:

StandardError (MAC address could not be autodetected.  Set the MAC address manually.):
    /vendor/gems/uuidtools-1.0.3/lib/uuidtools.rb:241:in `timestamp_create'
    /vendor/gems/uuidtools-1.0.3/lib/uuidtools.rb:229:in `synchronize'
    /vendor/gems/uuidtools-1.0.3/lib/uuidtools.rb:229:in `timestamp_create'

It seemed UUIDTools was trying to get the the network card’s MAC address (I’d guess to collect entropy), but couldn’t for some reason. I should also note that this is all running on an Ubuntu Hardy Heron 8.04, 512MB slice over at Slicehost (yes, that’s a referral link, use it! :-).

It turns out that UUIDTools was trying to use ifconfig to read the MAC address, but ifconfig wasn’t in the PATH. Since the application is now running under mod_rails, the relevant PATH is Apache’s PATH, which doesn’t include /sbin by default.

So, a quick edit of /etc/init.d/apache2 to change

ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"


ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin:/sbin"

and a sudo /etc/init.d/apache2 restart was all it took to get the app back up and running.