Skip to content

Instantly share code, notes, and snippets.

@tpitale
Created January 3, 2014 04:09
Show Gist options
  • Save tpitale/8232559 to your computer and use it in GitHub Desktop.
Save tpitale/8232559 to your computer and use it in GitHub Desktop.
Basic start/stop upstart init conf for a ruby script. May require modification to run in /bin/bash or if you need to source rbenv or chruby.
# /etc/init/ruby-example-upstart.conf
description "Ruby example upstart conf"
# change to the user you want to run this ruby script as
setuid deploy
setgid deploy
# This starts upon bootup and stops on shutdown
# check runlevel of running system with `runlevel` command
start on runlevel [2345]
stop on runlevel [06]
# controls for respawning this process if it dies
respawn # yes, we want this to respawn
respawn limit 3 30 # only try 3x to respawn in 30 seconds
# Setup any env variable you want to use, you can also pass variables into the start/stop
env RAILS_ENV=production
# pre-start script
# use this for any pre-start stuff
# end script
script
# give us a login shell to load rbenv/chruby, YMMV
exec /bin/bash -lc <<EOS
cd /where/the/ruby/script/is
exec bin/ruby-script -e ${RAILS_ENV} # or whatever params you need
EOS
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment