Probably a big "well, duh" moment for those more *nix experienced than me, but perhaps it will help some anyway.
So we upgraded ruby and rubygems on a machine last night, and after doing so found that a Rails script called by cron could no longer find the mysql gem. No problem I thought, I'll just reinstall it... but then "gem install mysql" reports an error:
/usr/local/bin/ruby extconf.rb install mysql checking for mysql_query() in -lmysqlclient... no checking for main() in -lm... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lz... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lsocket... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lnsl... no checking for mysql_query() in -lmysqlclient... no *** extconf.rb failed ***
Poo. Google quickly solves this issue:
gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
mysql gem installs without a hitch, happy again! So let's run the script: KABOOM.
custom_require.rb:36:in `gem_original_require': no such file to load -- mysql (MissingSourceFile)
WTF? I just installed it?! Let's see, "gem list" shows it, irb can require it, ./script/console can retrieve records... what's going on?
Check the cron command again: hmm, we're calling /usr/bin/ruby.
ruby -vreports 1.8.7, but
/usr/bin/ruby -vreports 1.8.5.
which rubytells us /usr/local/bin/ruby. Let's try this:
mv /usr/bin/ruby /usr/bin/ruby-1.8.5 ln -s /usr/local/bin/ruby /usr/bin/ruby
Cross fingers, try our cron script again, this time it works!