summaryrefslogtreecommitdiff
path: root/develop_server.sh
diff options
context:
space:
mode:
Diffstat (limited to 'develop_server.sh')
-rwxr-xr-xdevelop_server.sh103
1 files changed, 103 insertions, 0 deletions
diff --git a/develop_server.sh b/develop_server.sh
new file mode 100755
index 0000000..8c2f27f
--- /dev/null
+++ b/develop_server.sh
@@ -0,0 +1,103 @@
1#!/usr/bin/env bash
2##
3# This section should match your Makefile
4##
5PY=${PY:-python}
6PELICAN=${PELICAN:-pelican}
7PELICANOPTS=
8
9BASEDIR=$(pwd)
10INPUTDIR=$BASEDIR/content
11OUTPUTDIR=$BASEDIR/output
12CONFFILE=$BASEDIR/pelicanconf.py
13
14###
15# Don't change stuff below here unless you are sure
16###
17
18SRV_PID=$BASEDIR/srv.pid
19PELICAN_PID=$BASEDIR/pelican.pid
20
21function usage(){
22 echo "usage: $0 (stop) (start) (restart) [port]"
23 echo "This starts Pelican in debug and reload mode and then launches"
24 echo "an HTTP server to help site development. It doesn't read"
25 echo "your Pelican settings, so if you edit any paths in your Makefile"
26 echo "you will need to edit your settings as well."
27 exit 3
28}
29
30function alive() {
31 kill -0 $1 >/dev/null 2>&1
32}
33
34function shut_down(){
35 PID=$(cat $SRV_PID)
36 if [[ $? -eq 0 ]]; then
37 if alive $PID; then
38 echo "Stopping HTTP server"
39 kill $PID
40 else
41 echo "Stale PID, deleting"
42 fi
43 rm $SRV_PID
44 else
45 echo "HTTP 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
62function start_up(){
63 local port=$1
64 echo "Starting up Pelican and HTTP server"
65 shift
66 $PELICAN --debug --autoreload -r $INPUTDIR -o $OUTPUTDIR -s $CONFFILE $PELICANOPTS &
67 pelican_pid=$!
68 echo $pelican_pid > $PELICAN_PID
69 cd $OUTPUTDIR
70 $PY -m pelican.server $port &
71 srv_pid=$!
72 echo $srv_pid > $SRV_PID
73 cd $BASEDIR
74 sleep 1
75 if ! alive $pelican_pid ; then
76 echo "Pelican didn't start. Is the Pelican package installed?"
77 return 1
78 elif ! alive $srv_pid ; then
79 echo "The HTTP server didn't start. Is there another service using port" $port "?"
80 return 1
81 fi
82 echo 'Pelican and HTTP server processes now running in background.'
83}
84
85###
86# MAIN
87###
88[[ ($# -eq 0) || ($# -gt 2) ]] && usage
89port=''
90[[ $# -eq 2 ]] && port=$2
91
92if [[ $1 == "stop" ]]; then
93 shut_down
94elif [[ $1 == "restart" ]]; then
95 shut_down
96 start_up $port
97elif [[ $1 == "start" ]]; then
98 if ! start_up $port; then
99 shut_down
100 fi
101else
102 usage
103fi