Created
January 21, 2011 05:36
-
-
Save rrrodrigo/789283 to your computer and use it in GitHub Desktop.
init.d script for starting multiple unicorn-based apps
This file contains 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
#!/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