Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a very simple Ruby application which uses Thin and Bundler that I need to stick on an Ubuntu box.

I've got as far as getting Ruby, bundler etc installed on the server, but am having trouble running the application itself.

Essentially I need a nice way of starting, stopping and restarting the application via capistrano.

My init.d script looks pretty much like this:

DAEMON=/home/ubuntu/apps/my_app/shared/bundle/ruby/1.8/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)
        cd /home/ubuntu/apps/my_app/current && bundle exec thin start -d -C /etc/thin/my_app.yml
        ;;
  stop)
        cd /home/ubuntu/apps/my_app/current && bundle exec thin stop -d -C /etc/thin/my_app.yml
        ;;
  restart)
        cd /home/ubuntu/apps/my_app/current && bundle exec thin restart -d -C /etc/thin/my_app.yml
        ;;
  *)
        echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
        exit 3
        ;;
esac

This results in:

/home/ubuntu/apps/my_app/shared/bundle/ruby/1.8/gems/thin-1.3.1/lib/thin/daemonizing.rb:51:in `daemonize': uninitialized constant Thin::Daemonizable::Daemonize (NameError)

Running sudo bundle exec thin start from the application root on the server works just fine (although not as a daemon).

Therefore, how can I set this application up so that it'll start up as a daemon and be controllable via an init.d script / monit etc?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You could create binstubs. using these the init-script should be like any other. thin just needs --damonize as parameter if you do not specify it in your thin.yaml. With thin install thin generates an init-script for you

BUNDLE INSTALL --BINSTUBS

If you use the --binstubs flag in bundle install(1), Bundler will automatically create a directory (which defaults to app_root/bin) containing all of the executables available from gems in the bundle.

After using --binstubs, bin/rspec spec/my_spec.rb is identical to bundle exec rspec spec/my_spec.rb.

http://gembundler.com/man/bundle-exec.1.html

Based on these features this works for me:

bundle install --binstubs
./bin/thin install
/etc/init.d/thin start
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.