Reputation: 5191
I'm trying to setup Apache/Thin to power my Rails 3.2.9 application, which means setting up both Apache and Thin as daemons. I'm using RVM/gemset that runs Ruby 1.9.3-p286, however, my daemons don't seem to want to use it, instead, opting for some non-RVM system installed Ruby 1.8.7.
When I go to start thin, this is the error I receive:
ubuntu@ip-1-1-1-1:~/www/mydomain/mysite$ /etc/init.d/thin start
/usr/local/rvm/gems/ruby-1.9.3-p286@mysite/gems/eventmachine-1.0.0/lib/rubyeventmachine.so: [BUG] Segmentation fault
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
Aborted (core dumped)
Similarly, using the same command with sudo
yields:
ubuntu@ip-1-1-1-1:~$ sudo /etc/init.d/thin start
[start] /etc/thin/mysite.yml ...
Starting server on 127.0.0.1:5000 ...
# However, it refuses connections and crashes, evidenced by:
ubuntu@ip-1-1-1-1:~/www/mydomain/mysite/log$ cat thin.5000.log
>> Writing PID to tmp/pids/thin.5000.pid
>> Using rack adapter
>> Exiting!
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- bundler/setup (LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
...
I think the segmentation fault is due to the wrong version of Ruby. Clearly, it is using 1.8.7, which isn't the Ruby I want. However, checking the ruby version otherwise seems to look OK:
ubuntu@ip-1-1-1-1:~$ which ruby
/usr/local/rvm/rubies/ruby-1.9.3-p286/bin/ruby
ubuntu@ip-1-1-1-1:~$ ruby -v
ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-linux]
And here it is again run under sudo
:
ubuntu@ip-1-1-1-1:~$ sudo which ruby
/usr/bin/ruby
ubuntu@ip-1-1-1-1:~$ sudo ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
How do I get my system to use Ruby 1.9.3 when I run Thin as a daemon, and avoid these nasty errors?
EDIT:
Here's what my /etc/init.d/thin file looks like (it's auto-generated using thin install, I believe):
#!/bin/sh
### BEGIN INIT INFO
# Provides: thin
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: thin initscript
# Description: thin
### END INIT INFO
# Original author: Forrest Robertson
# Do NOT "set -e"
DAEMON=/usr/local/bin/thin
SCRIPT_NAME=/etc/init.d/thin
CONFIG_PATH=/etc/thin
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
case "$1" in
start)
$DAEMON start --all $CONFIG_PATH
;;
stop)
$DAEMON stop --all $CONFIG_PATH
;;
restart)
$DAEMON restart --all $CONFIG_PATH
;;
*)
echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
exit 3
;;
esac
Upvotes: 0
Views: 2299
Reputation: 5191
Figured it out (or at least, I got it working one way...)
Using this suggestion on the RVM site...
thin
) is installed in one of your RVM gemsets.rvm wrapper ruby-1.9.3@mygemset bootup thin
, replacing parameters as appropriate to your installation. It will make a script /usr/local/rvm/bin/bootup_thin
. This wrapper will load thin with the gemset you specified in your call./etc/init.d/thin
script. Make the script call the generated Ruby wrapper by setting DAEMON=/usr/local/bin/thin
to DAEMON=/usr/local/rvm/bin/bootup_thin
rvm gemset use
, then run bundle install
to install the necessary gems into the gemset used by the daemon.With that, I got my server running with Apache/Thin. For those looking to do the same, use these pages.
1st: http://articles.slicehost.com/2008/5/6/ubuntu-hardy-thin-web-server-for-ruby
2nd: http://articles.slicehost.com/2008/5/6/ubuntu-hardy-apache-rails-and-thin
Upvotes: 3
Reputation: 13069
You can edit /etc/init.d/thin and change this part:
run_action() {
ACTION="$1"
if [ -x /usr/bin/ruby1.8 ]; then
/usr/bin/ruby1.8 $DAEMON $ACTION --all /etc/thin1.8
fi
if [ -x /usr/bin/ruby1.9.1 ]; then
/usr/bin/ruby1.9.1 $DAEMON $ACTION --all /etc/thin1.9.1
fi
}
Upvotes: 0