Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
Created March 6, 2013 15:25
Show Gist options
  • Save hgdeoro/5100058 to your computer and use it in GitHub Desktop.
Save hgdeoro/5100058 to your computer and use it in GitHub Desktop.
Init script for Unicorn+Snorby
#! /bin/sh
#
# Snorby Control the Unicorn+Snorby server
#
# chkconfig: - 90 10
# config: /home/snorby/snorby/unicorn.conf.rb
# pidfile: /var/run/snorby/unicorn.pid
# Source function library.
. /etc/rc.d/init.d/functions
RETVAL=0
PROCNAME=unicorn_rails
USER=snorby
PGREP="-u $USER $PROCNAME"
CONFIG="/home/snorby/snorby/unicorn.conf.rb"
PIDFILE="/var/run/snorby/unicorn.pid"
mkdir -p /var/run/snorby 2> /dev/null
chown snorby /var/run/snorby
mkdir -p /var/log/snorby 2> /dev/null
chown snorby /var/log/snorby
# See how we were called.
case "$1" in
start)
echo -n "Starting Unicorn+Snorby server: "
su -l -s /bin/bash -c "unicorn_rails --daemonize --env production --daemonize --config-file $CONFIG" $USER
RETVAL=$?
if [ $RETVAL -eq 0 ]
then
echo_success
else
echo_failure
fi
echo
;;
stop)
echo -n "Stopping Unicorn+Snorby server:: "
su -l -s /bin/bash -c "kill $(cat $PIDFILE) > /dev/null 2> /dev/null" $USER
RETVAL=$?
if [ $RETVAL -eq 0 ]
then
echo_success
else
echo_failure
fi
echo
;;
status)
pids=$(pgrep $PGREP)
if [ -z "$pids" ] ; then
echo "Unicorn+Snorby NO esta ejecutandose..."
RETVAL=1
else
echo -n "Unicorn+Snorby en ejecucion - Pids: "
for pid in $pids ; do
echo -n "$pid "
done
echo ""
RETVAL=0
fi
;;
restart|reload)
$0 stop
$0 start
RETVAL=$?
;;
*)
echo "Usage: snorby {start|stop|status|restart}"
exit 1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment