Using RVM and Ruby-based services that start via init.d
To use any Ruby application that needs to be started with init.d (e.g., god, unicorn, thin) with RVM, you need to generate a wrapper script. Namely, you need to set it up so that there is an alternative executable that loads the correct gemset.
As an example, if you'd installed unicorn without RVM, you might have created an init.d script for it that looks like this one from a gist that ranked highly for the search "init.d script for unicorn" at the time of this writing.
In that script, the command to start unicorn is given as
However, if you are using RVM, you might have installed unicorn under Ruby 1.9.3 p0 in a gemset called "rails31" (aka. "ruby-1.9.3-p0@rails31"). In that case, unicorn_rails would not be installed under /usr/bin, but would be under ~/.rvm/gems/ruby-1.9.3-p0@rails31/bin, and you would need to set the environment variables up correctly to have it run as expected.
Instead of doing it manually, you can create a wrapper script for unicorn using RVM:
rvm wrapper ruby-1.9.3-p0@rails31 bootup unicorn_rails
Running this command will generate the executable bootup_unicorn_rails in ~/.rvm/bin or, if you have installed RVM system wide, in /usr/local/rvm/bin.
Thus, when setting up your init files, instead of using the direct path to unicorn_rails, you would instead use the path to bootup_unicorn_rails.
Use wrapper scripts for any Ruby gem executable you need to run with init.d.