comparison develop_server.sh @ 0:4cd9b65e10e4

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