Running Rails Thin Service Applications

I am trying to work as a service on my web server. After running "sudo thin install" thin created the following file in the /etc/init.d/thin file

#!/bin/sh DAEMON=/usr/local/lib/ruby/gems/1.9.1/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 

When thin service starts, the following is performed:

  thin start --all / etc / thin 
This scans all yaml configuration files that determine how to work with thin for each installed application. This does not work.

I see in my magazines:

 /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/runtime.rb:27:in `block in setup': You have already activated eventmachine 0.12.6, but your Gemfile requires eventmachine 0.12.11. Consider using bundle exec. (Gem::LoadError) from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `block in each' from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `each' from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `each' from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/runtime.rb:17:in `setup' from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler.rb:100:in `setup' from /srv/app/current/config/boot.rb:8:in `<top (required)>' from <internal:lib/rubygems/custom_require>:29:in `require' from <internal:lib/rubygems/custom_require>:29:in `require' from /srv/app/current/config/application.rb:1:in `<top (required)>' from <internal:lib/rubygems/custom_require>:29:in `require' from <internal:lib/rubygems/custom_require>:29:in `require' from /srv/app/current/config/environment.rb:2:in `<top (required)>' from <internal:lib/rubygems/custom_require>:29:in `require' from <internal:lib/rubygems/custom_require>:29:in `require' from /srv/app/current/config.ru:3:in `block in <main>' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize' from /srv/app/current/config.ru:1:in `new' from /srv/app/current/config.ru:1:in `<main>' from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/rack/adapter/loader.rb:36:in `eval' from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/rack/adapter/loader.rb:36:in `load' from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/rack/adapter/loader.rb:45:in `for' from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/controllers/controller.rb:163:in `load_adapter' from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/controllers/controller.rb:67:in `start' from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/runner.rb:177:in `run_command' from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/runner.rb:143:in `run!' from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/bin/thin:6:in `<top (required)>' from /usr/local/lib/ruby/gems/1.9.1/bin/thin:19:in `load' from /usr/local/lib/ruby/gems/1.9.1/bin/thin:19:in `<main>' 

When capistrano is deployed, I cache my package in the $ APP_PATH / shared / bundle directory; so this explains why the thin one complains that the gems are not set because the thin service does not look in $ APP_PATH / shared / bundle

It works:

 cd $APP_PATH/current; bundle exec thin start -d -C /etc/thin/app_x.yml 

but this is not how the thin utility file in /etc/init.d/thin works. I think I could write my own. I just do not want to solve a problem that has already been solved.

+4
source share
1 answer

I came up with this, but it does not seem to me that this is the best solution, because it does not use the thin "allall" option, where it reads configuration files from the directory. Instead, I changed the file that starts / stops / restarts the thin service, so for each application I give it a specific command to start / stop / restart. I am sure that this team can be improved, but so far it works for my needs.

 #!/bin/sh # This is a pretty bad, but effective workaround for starting thin as a service per application. DAEMON=/usr/local/lib/ruby/gems/1.9.1/bin/thin # DAEMON=/usr/local/bin/bundler 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) cd /srv/hub/current && bundle exec thin start -d -C /etc/thin/hub.yml ;; stop) cd /srv/hub/current && bundle exec thin stop -d -C /etc/thin/hub.yml ;; restart) cd /srv/hub/current && bundle exec thin restart -d -C /etc/thin/hub.yml ;; *) echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2 exit 3 ;; esac 
+1
source

All Articles