さくらインターネットの VPS で cron で ruby のスクリプトが動かない

rvm で 1.9.3-p0 をインストールしたがトラブルが…。

libyaml の警告を消す

It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.

yum ではインストールできないようなので、

$ wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
$ tar xzvf yaml-0.1.4.tar.gz
$ cd yaml-0.1.4
$ ./configure
$ make
$ sudo make install

その後、

$ rvm reinstall ruby-1.9.3-p0

tlsmail の警告を消す

/usr/local/rvm/gems/ruby-1.9.3-p0/gems/tlsmail-0.0.1/lib/net/smtp.rb:806: warning: already initialized constant SMTPSession

smtp.rb と pop.rb を直接修正する必要があるらしい。

  Net.instance_eval {remove_const :SMTPSession} if defined?(SMTPSession)
  SMTPSession = SMTP
  Net.instance_eval {remove_const :POP} if defined?(POP)
  Net.instance_eval {remove_const :POPSession} if defined?(POPSession)
  Net.instance_eval {remove_const :POP3Session} if defined?(POP3Session)
  POP = POP3
  POPSession  = POP3
  POP3Session = POP3
  (snip)
  Net.instance_eval {remove_const :APOPSession} if defined?(APOPSession)
  APOPSession = APOP

コマンドラインから実行すると動作するが、cron で実行すると動かない

:1:in `require': cannot load such file -- rubygems.rb (LoadError)

GEM_HOME や RUBYLIB を設定しないといけない。crontab -e で先頭に以下の行を追加した。

GEM_HOME=/usr/local/rvm/gems/ruby-1.9.3-p0
RUBYLIB=/usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/x86_64-linux/:/usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/

RUBYLIB は正解かどうかわからない。アーキテクチャ依存のパスを書く必要があるのかいまいちスッキリしない。