Skip to content

Instantly share code, notes, and snippets.

@mvickers
Created October 20, 2011 05:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mvickers/1300467 to your computer and use it in GitHub Desktop.
Save mvickers/1300467 to your computer and use it in GitHub Desktop.
Basic Centos init script for Dancer apps
#!/bin/sh
#
# some_website - this script starts and stops some_website
#
# chkconfig: - 85 15
# description: Some website description
# pidfile: /var/run/plackup.some_website.pid
PID=/var/run/plackup.some_website.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
PORT=5001
WORKERS=32
DANCER_DIR="/opt/webapps/some_website"
DANCER_APP="$DANCER_DIR/bin/app.pl"
plackup="/usr/bin/plackup"
plackup_args="-E production -p $PORT -s Starman --pid=$PID --workers $WORKERS -D"
website="Some Website"
lockfile=/var/lock/subsys/plackup.some_website
start() {
[ -x $plackup ] || exit 5
[ -f $DANCER_APP ] || exit 6
echo -n $"Starting $website: "
$plackup $plackup_args -a $DANCER_APP 2>&1 > /dev/null
retval=$?
if [ $retval -eq 0 ]; then
success $"$website started"
touch $lockfile
else
failure $"Unable to start"
fi
echo
return $retval
}
stop() {
echo -n $"Stopping $website: "
if [ -f $PID ]; then
kill `cat $PID` 2>&1> /dev/null
retval=$?
[ $retval -eq 0 ] && success && rm -f $lockfile
echo
return $retval
fi
failure $"pid $PID not found"
echo
return 1
}
restart() {
stop
start
}
case "$1" in
start)
$1
;;
stop)
$1
;;
restart)
$1
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 2
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment