annotate develop_server.sh @ 20:137650a0be4e

Add requirements.txt.
author Brian Neal <bgneal@gmail.com>
date Sat, 27 Aug 2016 13:04:58 -0500
parents c4ec6945bb86
children
rev   line source
bgneal@0 1 #!/usr/bin/env bash
bgneal@0 2 ##
bgneal@0 3 # This section should match your Makefile
bgneal@0 4 ##
bgneal@0 5 PY=python
bgneal@0 6 PELICAN=pelican
bgneal@0 7 PELICANOPTS=
bgneal@0 8
bgneal@0 9 BASEDIR=$(pwd)
bgneal@0 10 INPUTDIR=$BASEDIR/content
bgneal@0 11 OUTPUTDIR=$BASEDIR/output
bgneal@0 12 CONFFILE=$BASEDIR/pelicanconf.py
bgneal@0 13
bgneal@0 14 ###
bgneal@0 15 # Don't change stuff below here unless you are sure
bgneal@0 16 ###
bgneal@0 17
bgneal@0 18 SRV_PID=$BASEDIR/srv.pid
bgneal@0 19 PELICAN_PID=$BASEDIR/pelican.pid
bgneal@0 20
bgneal@0 21 function usage(){
bgneal@0 22 echo "usage: $0 (stop) (start) (restart) [port]"
bgneal@0 23 echo "This starts pelican in debug and reload mode and then launches"
bgneal@0 24 echo "A pelican.server to help site development. It doesn't read"
bgneal@0 25 echo "your pelican options so you edit any paths in your Makefile"
bgneal@0 26 echo "you will need to edit it as well"
bgneal@0 27 exit 3
bgneal@0 28 }
bgneal@0 29
bgneal@0 30 function alive() {
bgneal@0 31 kill -0 $1 >/dev/null 2>&1
bgneal@0 32 }
bgneal@0 33
bgneal@0 34 function shut_down(){
bgneal@0 35 PID=$(cat $SRV_PID)
bgneal@0 36 if [[ $? -eq 0 ]]; then
bgneal@0 37 if alive $PID; then
bgneal@0 38 echo "Killing pelican.server"
bgneal@0 39 kill $PID
bgneal@0 40 else
bgneal@0 41 echo "Stale PID, deleting"
bgneal@0 42 fi
bgneal@0 43 rm $SRV_PID
bgneal@0 44 else
bgneal@0 45 echo "pelican.server PIDFile not found"
bgneal@0 46 fi
bgneal@0 47
bgneal@0 48 PID=$(cat $PELICAN_PID)
bgneal@0 49 if [[ $? -eq 0 ]]; then
bgneal@0 50 if alive $PID; then
bgneal@0 51 echo "Killing Pelican"
bgneal@0 52 kill $PID
bgneal@0 53 else
bgneal@0 54 echo "Stale PID, deleting"
bgneal@0 55 fi
bgneal@0 56 rm $PELICAN_PID
bgneal@0 57 else
bgneal@0 58 echo "Pelican PIDFile not found"
bgneal@0 59 fi
bgneal@0 60 }
bgneal@0 61
bgneal@0 62 function start_up(){
bgneal@0 63 local port=$1
bgneal@0 64 echo "Starting up Pelican and pelican.server"
bgneal@0 65 shift
bgneal@0 66 $PELICAN --debug --autoreload -r $INPUTDIR -o $OUTPUTDIR -s $CONFFILE $PELICANOPTS &
bgneal@0 67 pelican_pid=$!
bgneal@0 68 echo $pelican_pid > $PELICAN_PID
bgneal@0 69 cd $OUTPUTDIR
bgneal@0 70 $PY -m pelican.server $port &
bgneal@0 71 srv_pid=$!
bgneal@0 72 echo $srv_pid > $SRV_PID
bgneal@0 73 cd $BASEDIR
bgneal@0 74 sleep 1
bgneal@0 75 if ! alive $pelican_pid ; then
bgneal@0 76 echo "Pelican didn't start. Is the pelican package installed?"
bgneal@0 77 return 1
bgneal@0 78 elif ! alive $srv_pid ; then
bgneal@0 79 echo "pelican.server didn't start. Is there something else which uses port 8000?"
bgneal@0 80 return 1
bgneal@0 81 fi
bgneal@0 82 echo 'Pelican and pelican.server processes now running in background.'
bgneal@0 83 }
bgneal@0 84
bgneal@0 85 ###
bgneal@0 86 # MAIN
bgneal@0 87 ###
bgneal@0 88 [[ ($# -eq 0) || ($# -gt 2) ]] && usage
bgneal@0 89 port=''
bgneal@0 90 [[ $# -eq 2 ]] && port=$2
bgneal@0 91
bgneal@0 92 if [[ $1 == "stop" ]]; then
bgneal@0 93 shut_down
bgneal@0 94 elif [[ $1 == "restart" ]]; then
bgneal@0 95 shut_down
bgneal@0 96 start_up $port
bgneal@0 97 elif [[ $1 == "start" ]]; then
bgneal@0 98 if ! start_up $port; then
bgneal@0 99 shut_down
bgneal@0 100 fi
bgneal@0 101 else
bgneal@0 102 usage
bgneal@0 103 fi