Skip to content

Instantly share code, notes, and snippets.

@fgbreel
Last active February 2, 2016 22:01
Show Gist options
  • Save fgbreel/d903da91aecd29257edd to your computer and use it in GitHub Desktop.
Save fgbreel/d903da91aecd29257edd to your computer and use it in GitHub Desktop.
unicorn lsb init script for huginn
#! /bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $syslog $networking
# Required-Stop: $syslog $networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Unicorn APP Server
# Description: Debian init script for the Unicorn APP Server
# scheduler
### END INIT INFO
PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin
# application variables
NAME="unicorn"
TIMEOUT=${TIMEOUT-60}
PWD=/var/www/huginn
DAEMON="/usr/local/bin/unicorn"
DAEMON_OPTS="-D -c $PWD/config/unicorn.rb -E production"
PIDFILE="$PWD/tmp/pids/unicorn.pid"
. /lib/lsb/init-functions
case "$1" in
start)
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
if [ "$status" = "0" ]; then
exit
fi
fi
log_daemon_msg "Starting unicorn app server" "$NAME"
cd $PWD || exit 1
start-stop-daemon --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON --start -- $DAEMON_OPTS
log_end_msg $?
;;
stop)
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
if [ "$status" = "0" ]; then
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
/bin/rm -f $PIDFILE
fi
else
log_daemon_msg "$NAME process is not running"
log_end_msg 0
fi
;;
upgrade)
if [ -e $PIDFILE ]; then
start-stop-daemon --signal HUP --pidfile $PIDFILE --stop
log_success_msg "$NAME process reloaded successfully"
else
log_failure_msg "$PIDFILE does not exists"
fi
;;
reload)
if [ -e $PIDFILE ]; then
start-stop-daemon --signal USR2 --pidfile $PIDFILE --stop
log_success_msg "$NAME process reloaded successfully"
else
log_failure_msg "$PIDFILE does not exists"
fi
;;
restart)
$0 stop && sleep 1 && $0 start
;;
status)
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && exit 0 || exit $?
else
log_daemon_msg "$NAME process is not running"
log_end_msg 0
fi
;;
*)
echo "Usage: $0 {start|stop|reload|restart|upgrade|status}"
exit 2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment