Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/sh
- ### BEGIN INIT INFO
- # Provides: unicorn
- # Required-Start: $all
- # Required-Stop: $all
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: starts the unicorn app server
- # Description: starts unicorn using start-stop-daemon
- ### END INIT INFO
- usage() {
- echo "Usage: $0 {rails_env} {start|stop|force-stop|restart|force-reload|reload|upgrade|commit|rollback|reopen-logs|status|inc|dec}" >&2
- }
- RAILS_ENV=$1
- APP_ROOT=/var/www/$RAILS_ENV/current
- PIDFILE=$APP_ROOT/tmp/pids/unicorn.pid
- UNICORN_CONFIG=$APP_ROOT/config/unicorn/$RAILS_ENV.rb
- UNICORN_UID=deployer
- UNICORN_GID=deployer
- UNICORN_PROCESS_NAME=unicorn_rails
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- DAEMON=/usr/local/rvm/gems/ree-1.8.7-2010.02/bin/$UNICORN_PROCESS_NAME
- DAEMON_OPTS="-D -E $RAILS_ENV -c $UNICORN_CONFIG"
- NAME=unicorn
- DESC=unicorn
- test -x $DAEMON || exit 0
- # Include unicorn defaults if available
- if [ -f /etc/default/unicorn ] ; then
- . /etc/default/unicorn
- fi
- if [ -z $RAILS_ENV ] ; then
- usage && exit 1
- fi
- set -e
- . /lib/lsb/init-functions
- sig() {
- test -s "$2" && kill -s $1 `cat $2`
- }
- start() {
- start-stop-daemon --start --quiet \
- --chdir $APP_ROOT \
- --chuid $UNICORN_UID:$UNICORN_GID \
- --exec $DAEMON -- $DAEMON_OPTS || true
- }
- case "$2" in
- start)
- echo -n "Starting $DESC: "
- sig 0 $PIDFILE || start
- echo "$NAME."
- ;;
- stop)
- echo -n "Stopping $DESC: "
- sig QUIT $PIDFILE || true
- echo "$NAME."
- ;;
- force-stop)
- echo -n "Force stopping $DESC: "
- sig TERM $PIDFILE || true
- echo "$NAME."
- ;;
- restart|force-reload)
- echo -n "Restarting $DESC: "
- sig 0 $PIDFILE || ( start && echo "$NAME." && exit 0 )
- sig USR2 $PIDFILE && sleep 4 && sig QUIT $PIDFILE.oldbin && \
- echo -n "restarted "
- echo "$NAME."
- ;;
- reload)
- echo -n "Reloading $DESC configuration: "
- sig HUP $PIDFILE || echo -n "not running "
- echo "$NAME."
- ;;
- upgrade)
- echo -n "Upgrading $DESC: "
- sig USR2 $PIDFILE && sleep 4 && sig WINCH $PIDFILE.oldbin && \
- echo -n "check app, then commit or rollback "
- echo "$NAME."
- ;;
- commit)
- echo -n "Commit $DESC to new master: "
- sig 0 $PIDFILE || ( echo "no new master found" && exit 0 )
- sig QUIT $PIDFILE.oldbin || echo -n "no previous master found "
- echo "$NAME."
- ;;
- rollback)
- echo -n "Rollback $DESC to previous master: "
- sig 0 $PIDFILE.oldbin || ( echo "no previous master found" && exit 0 )
- sig HUP $PIDFILE.oldbin && sig QUIT $PIDFILE || true
- echo "$NAME."
- ;;
- reopen-logs)
- echo -n "Reopen $DESC logs: "
- sig USR1 $PIDFILE || true
- echo "$NAME."
- ;;
- status)
- status_of_proc -p $PIDFILE "$DAEMON" $NAME && exit 0 || exit $?
- ;;
- inc)
- echo -n "Increment $DESC workers by one: "
- sig TTIN $PIDFILE || echo -n "not running "
- echo "$NAME."
- ;;
- dec)
- echo -n "Decrement $DESC workers by one: "
- sig TTOU $PIDFILE || echo -n "not running "
- echo "$NAME."
- ;;
- *)
- usage
- exit 1
- ;;
- esac
- exit 0
Add Comment
Please, Sign In to add comment