Skip to content

Instantly share code, notes, and snippets.

@rrrodrigo
Created January 21, 2011 05:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rrrodrigo/789283 to your computer and use it in GitHub Desktop.
Save rrrodrigo/789283 to your computer and use it in GitHub Desktop.
init.d script for starting multiple unicorn-based apps
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: unicorn initscript
# Description: unicorn
### END INIT INFO
# Do NOT "set -e"
DAEMON=/opt/ruby/bin/unicorn_rails
SCRIPT_NAME=/etc/init.d/unicorn
APPS="app1:env1 app2:env2 app3:env3 app4:env4"
case "$1" in
start)
for app in $APPS; do
user=`echo $app | cut -d':' -f1`
environment=`echo $app | cut -d':' -f2`
su - $user -c "cd /web/$user/current && bundle exec unicorn_rails -c config/unicorn_$environment.config -E $environment -D"
done
;;
restart)
for app in $APPS; do
user=`echo $app | cut -d':' -f1`
kill -USR2 `cat /web/$user/shared/pids/unicorn.pid`
done
;;
stop)
for app in $APPS; do
user=`echo $app | cut -d':' -f1`
kill -TERM `cat /web/$user/shared/pids/unicorn.pid`
done
;;
*)
echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment