When using the /etc/init.d/thin script to run thin server as a service, I experienced the following error:
/home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find thin (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError)
from /home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
from /home/myuser/.rvm/gems/ruby-1.9.3-p125/bin/thin:18:in `
The problem is that the script is trying to start thin without rvm being loaded into shell.
My solution was to replace the default /etc/init.d/thin with this, which first declares the rvm_path and loads rvm into shell:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#!/bin/bash
# NOTE: script was written for an environment where rails is installed in the user's home directory
# you may need to adjust for your environment
export HOME="/home/myuser" # path to the user's home directory
export rvm_path="$HOME/.rvm" # path to RVM
export APP_PATH="$HOME/myapp" # path to your rails application
export CONFIG_PATH="$APP_PATH/config/thin.yml" # path to your thin yml
export RUBY_VER="1.9.3" # desired ruby version
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # load rvm into shell
cd $APP_PATH # navigate to rails app
rvm use $RUBY_VER # select desired ruby version
# using rvmsudo since ports privileged ports (< 1024) require su
case "$1" in
start)
rvmsudo thin start -C $CONFIG_PATH
;;
stop)
rvmsudo thin stop
;;
restart)
rvmsudo thin restart -C $CONFIG_PATH
;;
*)
echo "Specify {start|stop|restart}" >&2
exit 3
;;
esac
: |
Resources:
