Skip to content

Instantly share code, notes, and snippets.

@joshkraemer
Created February 7, 2012 22:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshkraemer/1762707 to your computer and use it in GitHub Desktop.
Save joshkraemer/1762707 to your computer and use it in GitHub Desktop.
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