Created
September 16, 2013 15:21
-
-
Save rhoml/6582094 to your computer and use it in GitHub Desktop.
Init for unicorn and puppet
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 | |
### BEGIN INIT INFO | |
# Provides: unicorn-puppet | |
# Required-Start: $local_fs $remote_fs $network $syslog | |
# Required-Stop: $local_fs $remote_fs $network $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: starts the unicorn app server | |
# Description: starts unicorn puppet | |
### END INIT INFO | |
USER=root | |
DAEMON=unicorn | |
APP_PATH=/etc/puppet | |
DAEMON_OPTS="-c $APP_PATH/unicorn.rb -D" | |
NAME=unicorn | |
DESC="Unicorn app for $USER" | |
PID=/var/run/puppet/puppet_unicorn.pid | |
PATH_BIN=/usr/local | |
# Tooks this function from https://gist.github.com/zmalltalker/5539976 | |
readpid() { | |
if [ -f $PID ]; then | |
read unicorn_pid < $PID | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
case "$1" in | |
start) | |
CD_TO_APP_DIR="cd $APP_PATH" | |
START_DAEMON_PROCESS="${PATH_BIN}/bin/$DAEMON $DAEMON_OPTS" | |
echo -n "Starting $DESC: " | |
$CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS | |
echo "$NAME." | |
;; | |
stop) | |
echo -n "Stopping $DESC: " | |
kill -QUIT `cat $PID` | |
echo "$NAME." | |
;; | |
restart) | |
echo -n "Restarting $DESC: " | |
kill -USR2 `cat $PID` | |
echo "$NAME." | |
;; | |
status) | |
if readpid; then | |
ps -p $unicorn_pid >/dev/null 2>&1 | |
echo "Unicorn running" | |
retval=0 | |
else | |
echo "Unicorn not running" | |
retval=4 | |
fi | |
;; | |
reload) | |
echo -n "Reloading $DESC configuration: " | |
kill -HUP `cat $PID` | |
echo "$NAME." | |
;; | |
rotate) | |
echo -n "Rotating logs $DESC: " | |
kill -USR1 `cat $PID` | |
echo "$NAME." | |
;; | |
*) | |
echo "Usage: $NAME {start|stop|status|restart|reload}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment