Created
February 7, 2012 22:56
-
-
Save joshkraemer/1762707 to your computer and use it in GitHub Desktop.
Unicorn init.d script
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
#!/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 | |
SCRIPT_NAME=/etc/init.d/unicorn | |
USR=deployer | |
ENV=production | |
APPDIR=/home/$USR/apps | |
APPS="`ls $APPDIR`" | |
case "$1" in | |
start) | |
for APPNAME in $APPS; do | |
APP=`echo $APPNAME` | |
echo -n "Starting Unicorn server for $APP..." | |
su - $USR -c "cd $APPDIR/$APP/current ; bundle exec unicorn_rails -c config/unicorn.rb -D -E $ENV" | |
echo "[ Done ]" | |
done | |
;; | |
restart|reload) | |
for APPNAME in $APPS; do | |
APP=`echo $APPNAME` | |
echo -n "Restarting Unicorn server for $APP..." | |
su - $USR -c "kill -s USR2 `cat $APPDIR/$APP/shared/pids/unicorn.pid`" | |
echo "[ Done ]" | |
done | |
;; | |
stop) | |
for APPNAME in $APPS; do | |
APP=`echo $APPNAME` | |
echo -n "Stopping Unicorn server for $APP..." | |
su - $USR -c "kill -s QUIT `cat $APPDIR/$APP/shared/pids/unicorn.pid`" | |
echo "[ Done ]" | |
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