Skip to content

Instantly share code, notes, and snippets.

@haad
Last active December 23, 2015 11:09
Show Gist options
  • Save haad/6626392 to your computer and use it in GitHub Desktop.
Save haad/6626392 to your computer and use it in GitHub Desktop.
Run rails application from upstart with start-stop-daemon
description "Rails Application"
start on runlevel [2345]
stop on runlevel [!2345]
console log
respawn
chdir /srv/apps/rails_path/current
env APP_NAME="rails-app"
env HOME="/srv/apps/rails_path/current"
env GEM_PATH="/var/lib/ruby-gems/rails-app/gems/1.9.1"
env PATH="/sbin:/usr/sbin:/bin:/usr/bin:/var/lib/ruby-gems/rails-app/gems/1.9.1/bin"
env BUNDLE_PATH="/var/lib/ruby-gems/rails-app/gems/1.9.1/bin/bundle"
env RAILS_ENV="production"
env RAILS_PORT="3000"
pre-start script
start-stop-daemon --start -b -d ${HOME} -p ${HOME}/tmp/pids/thin.pid --exec ${BUNDLE_PATH} -m -- exec thin start -e ${RAILS_ENV} -p ${RAILS_PORT} -l $HOME/log/thin.log
sudo initctl emit ${APP_NAME}_start
end script
post-stop script
start-stop-daemon --stop -d ${HOME} -p ${HOME}/tmp/pids/thin.pid
sudo initctl emit ${APP_NAME}_stop
end script
@haad
Copy link
Author

haad commented Sep 19, 2013

Just setup BUNDLE_PATH and GEM_PATH to proper values they can be loaded from rvm in script.

@remkade
Copy link

remkade commented Sep 19, 2013

Why use start-stop-daemon? Upstart can handle it all for you (including properly respawning) if you don't daemonize or background Thin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment