Last active
December 23, 2015 11:09
-
-
Save haad/6626392 to your computer and use it in GitHub Desktop.
Run rails application from upstart with start-stop-daemon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
Just setup BUNDLE_PATH and GEM_PATH to proper values they can be loaded from rvm in script.