bgneal@0: #!/usr/bin/env bash bgneal@0: ## bgneal@0: # This section should match your Makefile bgneal@0: ## bgneal@0: PY=python bgneal@0: PELICAN=pelican bgneal@0: PELICANOPTS= bgneal@0: bgneal@0: BASEDIR=$(pwd) bgneal@0: INPUTDIR=$BASEDIR/content bgneal@0: OUTPUTDIR=$BASEDIR/output bgneal@0: CONFFILE=$BASEDIR/pelicanconf.py bgneal@0: bgneal@0: ### bgneal@0: # Don't change stuff below here unless you are sure bgneal@0: ### bgneal@0: bgneal@0: SRV_PID=$BASEDIR/srv.pid bgneal@0: PELICAN_PID=$BASEDIR/pelican.pid bgneal@0: bgneal@0: function usage(){ bgneal@0: echo "usage: $0 (stop) (start) (restart) [port]" bgneal@0: echo "This starts pelican in debug and reload mode and then launches" bgneal@0: echo "A pelican.server to help site development. It doesn't read" bgneal@0: echo "your pelican options so you edit any paths in your Makefile" bgneal@0: echo "you will need to edit it as well" bgneal@0: exit 3 bgneal@0: } bgneal@0: bgneal@0: function alive() { bgneal@0: kill -0 $1 >/dev/null 2>&1 bgneal@0: } bgneal@0: bgneal@0: function shut_down(){ bgneal@0: PID=$(cat $SRV_PID) bgneal@0: if [[ $? -eq 0 ]]; then bgneal@0: if alive $PID; then bgneal@0: echo "Killing pelican.server" bgneal@0: kill $PID bgneal@0: else bgneal@0: echo "Stale PID, deleting" bgneal@0: fi bgneal@0: rm $SRV_PID bgneal@0: else bgneal@0: echo "pelican.server PIDFile not found" bgneal@0: fi bgneal@0: bgneal@0: PID=$(cat $PELICAN_PID) bgneal@0: if [[ $? -eq 0 ]]; then bgneal@0: if alive $PID; then bgneal@0: echo "Killing Pelican" bgneal@0: kill $PID bgneal@0: else bgneal@0: echo "Stale PID, deleting" bgneal@0: fi bgneal@0: rm $PELICAN_PID bgneal@0: else bgneal@0: echo "Pelican PIDFile not found" bgneal@0: fi bgneal@0: } bgneal@0: bgneal@0: function start_up(){ bgneal@0: local port=$1 bgneal@0: echo "Starting up Pelican and pelican.server" bgneal@0: shift bgneal@0: $PELICAN --debug --autoreload -r $INPUTDIR -o $OUTPUTDIR -s $CONFFILE $PELICANOPTS & bgneal@0: pelican_pid=$! bgneal@0: echo $pelican_pid > $PELICAN_PID bgneal@0: cd $OUTPUTDIR bgneal@0: $PY -m pelican.server $port & bgneal@0: srv_pid=$! bgneal@0: echo $srv_pid > $SRV_PID bgneal@0: cd $BASEDIR bgneal@0: sleep 1 bgneal@0: if ! alive $pelican_pid ; then bgneal@0: echo "Pelican didn't start. Is the pelican package installed?" bgneal@0: return 1 bgneal@0: elif ! alive $srv_pid ; then bgneal@0: echo "pelican.server didn't start. Is there something else which uses port 8000?" bgneal@0: return 1 bgneal@0: fi bgneal@0: echo 'Pelican and pelican.server processes now running in background.' bgneal@0: } bgneal@0: bgneal@0: ### bgneal@0: # MAIN bgneal@0: ### bgneal@0: [[ ($# -eq 0) || ($# -gt 2) ]] && usage bgneal@0: port='' bgneal@0: [[ $# -eq 2 ]] && port=$2 bgneal@0: bgneal@0: if [[ $1 == "stop" ]]; then bgneal@0: shut_down bgneal@0: elif [[ $1 == "restart" ]]; then bgneal@0: shut_down bgneal@0: start_up $port bgneal@0: elif [[ $1 == "start" ]]; then bgneal@0: if ! start_up $port; then bgneal@0: shut_down bgneal@0: fi bgneal@0: else bgneal@0: usage bgneal@0: fi