Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zmalltalker/5539976 to your computer and use it in GitHub Desktop.
Save zmalltalker/5539976 to your computer and use it in GitHub Desktop.
init.d script for Unicorn with Gitorious
#!/bin/sh
### BEGIN INIT INFO
# Provides: gitorious-unicorn
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Control the Gitorious application server
# Description: Unicorn is Gitorious' application server, accepting
# requests via a frontend web server like Nginx
### END INIT INFO
# Source function library.
. /etc/init.d/functions
UNICORN_PIDFILE="/var/www/gitorious/app/tmp/pids/unicorn.pid"
start_unicorn() {
/var/www/gitorious/app/bin/unicorn -c config/unicorn.rb -D && echo_success || echo_failure
retval=$?
echo "Starting unicorn"
}
stop_unicorn() {
if _readpid; then
kill -QUIT $unicorn_pid && echo_success || echo_failure
echo "Stopping"
retval=0
else
retval=7
fi
}
restart_unicorn() {
stop_unicorn && start_unicorn
}
_readpid() {
if [ -f $UNICORN_PIDFILE ]; then
read unicorn_pid < $UNICORN_PIDFILE
return 0
else
return 1
fi
}
status_unicorn() {
if _readpid; then
ps -p $unicorn_pid >/dev/null 2>&1 && echo_success || echo_failure
echo "Unicorn status"
retval=0
else
echo_failure
echo "Unicorn status"
retval=4
fi
}
reload_unicorn() {
if _readpid; then
kill -USR2 $unicorn_pid && echo_success || echo_failure
echo "Reloading Unicorn"
retval=0
else
echo_failure
echo "Unicorn isn't running"
retval=7
fi
}
case "$1" in
start)
start_unicorn
;;
stop)
stop_unicorn
;;
restart)
restart_unicorn
;;
status)
status_unicorn
;;
reload)
reload_unicorn
;;
*)
echo "$0 start|stop|restart|reload|status"
retval=2
;;
esac
exit $retval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment