System-wide RVM installations are recommended for production deployments, but because /usr/bin/ruby is no longer the “correct” ruby, you need to tell all your moving parts about RVM.
Before installing ruby
Make sure you’ve installed the development libraries that ruby and all of your gems need to work. For AdGrok, that amounts to:
|
1 |
sudo apt-get install curl git-core build-essential libreadline-dev zlib1g-dev libssl-dev libxslt1-dev libmysqlclient-dev |
Finish the installation
After you install RVM, look at your /etc/profile. If you already have this section:
|
1 2 3 4 5 6 7 8 |
if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi |
you just need to copy the following into a new file, /etc/profile.d/rvm.sh:
|
1 |
[[ -s "/usr/local/lib/rvm" ]] && source "/usr/local/lib/rvm" |
I originally had this in /etc/bash.bashrc, but that broke the “bash -l” solution below (because “PS1″ wasn’t defined).
Fix rails runner crontabs
Cron’s default shell, /bin/sh, doesn’t load the “interactive shell” configuration, so RVM won’t be available.
RVM comes with a “rvm-shell” wrapper script to fix this issue. Edit your crontab and change the SHELL. Here’s my whole /etc/cron.d/example.cron:
|
1 2 3 4 5 6 7 |
PATH=/sbin:/bin:/usr/sbin:/usr/bin SHELL=/usr/local/bin/rvm-shell MAILTO=... RAILS_ENV=production # m h dom mon dow user command # World's most inefficient way to tell the time: */15 * * * * deploy cd /u/apps/adgrok/current && rails runner "puts Time.now" |
Fix monit/delayed_job
The author of RVM suggested you could omit the “as uid … and gid …” and use a /bin/su prefix to load RVM, but I couldn’t get it to work for me. I had to use the bash -l -c method, just like in my crontab:
|
1 2 3 4 5 |
check process delayed_job.0 with pidfile /u/apps/adgrok/shared/pids/delayed_job.0.pid start program = "/usr/local/bin/rvm-shell -c 'RAILS_ENV=production /u/apps/adgrok/current/script/delayed_job start -i 0'" as uid deploy and gid deploy stop program = "/usr/local/bin/rvm-shell -c 'RAILS_ENV=production /u/apps/adgrok/current/script/delayed_job stop -i 0'" as uid deploy and gid deploy if 2 restarts within 15 cycles then timeout |
Fix Phusion Passenger
When you installed passenger, you specified a “PassengerRuby” value. Change that from /usr/bin/ruby1.8 (or whatever), to RVM’s ruby. In my case, it was
|
1 |
PassengerRuby /usr/local/rvm/rubies/ruby-1.8.7-p302/bin/ruby |