Created
October 17, 2010 18:46
-
-
Save adrianpike/631125 to your computer and use it in GitHub Desktop.
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/bash | |
| # | |
| # /etc/rc.d/init.d/unicorn | |
| # unicorn: This script starts and stops a unicorn app | |
| # | |
| # Author: Adrian Pike | |
| # | |
| # Source function library. | |
| . /etc/init.d/functions | |
| # BEGIN USER CONFIGURATION # | |
| PROG="unicorn" | |
| APPPATH='/u/apps/leatherbound/current/' | |
| CONFIG='/u/apps/leatherbound/current/config/unicorn.rb' | |
| RAILS_ENV=production | |
| LBPATH=/usr/local/bin/unicorn_rails | |
| PIDFILE=/var/run/unicorn.pid | |
| # END USER CONFIGURATION # | |
| RETVAL=0 | |
| start() { | |
| echo -n "Starting $PROG: " | |
| cd $APPPATH | |
| $LBPATH -c $CONFIG -E production -D | |
| if [ $? -ne 0 ]; then | |
| echo "Errors in Configuration, unable to start." | |
| exit 1 | |
| fi | |
| } | |
| reload() { | |
| echo -n "Reloading $PROG: " | |
| kill -USR2 `cat $PIDFILE` | |
| sleep 10 | |
| # TODO: ENSURE THAT THE NEW ONE IS UP AND RUNNING | |
| kill -QUIT `cat $PIDFILE.oldbin` | |
| if [ $? -ne 0 ]; then | |
| echo "Unable to reload." | |
| exit 1 | |
| fi | |
| } | |
| stop() { | |
| echo -n "Stopping $PROG: " | |
| killproc $LBPATH | |
| RETVAL=$? | |
| echo | |
| [ $RETVAL -eq 0 ] && rm -f ${PIDFILE} | |
| } | |
| check() { | |
| $LBPATH -c -q -f $CONF | |
| } | |
| case "$1" in | |
| start) | |
| start | |
| ;; | |
| stop) | |
| stop | |
| ;; | |
| status) | |
| status unicorn | |
| ;; | |
| reload) | |
| reload | |
| ;; | |
| force-reload) | |
| restart | |
| ;; | |
| restart) | |
| stop | |
| start | |
| ;; | |
| *) | |
| echo "Usage: {start|stop|restart|reload|force-reload|status}" | |
| exit 1 | |
| ;; | |
| esac | |
| exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment