Skip to content

Instantly share code, notes, and snippets.

@dsc
Created March 29, 2010 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsc/347808 to your computer and use it in GitHub Desktop.
Save dsc/347808 to your computer and use it in GitHub Desktop.
pylons.sh -- fiddles with pylons
#! /bin/bash
function halp () {
cat <<-HALP
pylons -- Starts a Pylons app, creating logs and saving a pidfile.
Usage: $( basename $0 ) [INI_FILE]
If INI_FILE is not 'development.ini', stdout and stderr are redirected
to logs/pylons.log.
HALP
}
function fail () {
echo "PREDICTABLE FAILURE. $1"
if [ "$2" ]; then halp; fi
exit 1
}
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
halp; exit 0
fi
BASE="$PWD"
INI="development.ini"
if [[ "$1" != "" ]]; then
BASE=$( dirname "$1" )
INI="$1"
fi
ININAME=$(basename "$INI")
PIDFILE="$BASE/paste.pid"
if [[ $ININAME == "development.ini" || $ININAME == "dev.ini" ]]; then
paster serve --reload $INI
else
mkdir -p $BASE/logs
paster serve --reload $INI >$BASE/logs/pylons.log 2>&1 &
sleep 4
ps ux | fgrep -v 'grep|awk' | awk -F '[ \n\t]+' '/paster serve/ { print $2 }' >$PIDFILE 2>/dev/null
if [ ! -e $PIDFILE ] || [ -z "$(cat $PIDFILE)" ]; then
fail "Unable to find pidfile!"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment