Skip to content

Instantly share code, notes, and snippets.

@racke
Created June 23, 2015 09:58
Show Gist options
  • Save racke/ebb44eb52108ce5811b4 to your computer and use it in GitHub Desktop.
Save racke/ebb44eb52108ce5811b4 to your computer and use it in GitHub Desktop.
Generic plackup script for camps
#!/bin/bash
# determine camp number
for CAMPDIR in "$PWD" "${PWD%/*}" "${PWD%/*/*}"; do
if [[ $CAMPDIR =~ ([[:digit:]]+)$ ]]; then
CAMPNUMBER=${BASH_REMATCH[1]}
break
fi
done
if [ ! "$CAMPNUMBER" ]; then
echo "Can not determine camp number from $PWD." >&2;
exit 1;
fi
export PERL5LIB=$CAMPDIR/local/lib/perl5"${PERL5LIB:+:$PERL5LIB}";
export PERL5LIB=$CAMPDIR/local/lib/perl5/x86_64-linux"${PERL5LIB:+:$PERL5LIB}";
PID=$CAMPDIR/var/run/plackup-app.pid
PORT=50$CAMPNUMBER
WORKERS=2
APP_DIR="$PWD"
APP=$APP_DIR/bin/app.pl
plackup="$CAMPDIR/local/bin/plackup"
plackup_args="-E development -o 127.0.0.1 -p $PORT -s Starman --pid=$PID --workers $WORKERS -D"
website="camp $CAMPNUMBER on port $PORT"
lockfile=$CAMPDIR/var/run/plackup-app.lock
start() {
if [ ! -x $plackup ]; then
echo "Plackup not found at: $plackup.";
exit 5
fi
if [ ! -f $APP ]; then
echo "Application not found at: $APP.";
exit 6
fi
echo "Starting $website."
$plackup $plackup_args -a $APP 2>&1 > /dev/null
retval=$?
[ $retval = 0 ] && touch $lockfile
return $retval
}
stop() {
echo "Stopping $website."
if [ -f $PID ]; then
kill -QUIT `cat $PID` 2>&1> /dev/null
retval=$?
[ $retval -eq 0 ] && rm -f $lockfile ${PID}
fi
}
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