Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unicorn init.d script
#!/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