develop_server.sh

Sat, 20 Feb 2016 23:26:37 +0100

author
David Douard <david.douard@logilab.fr>
date
Sat, 20 Feb 2016 23:26:37 +0100
changeset 25
a0031622ab30
parent 0
e7f601f9db69
permissions
-rwxr-xr-x

add pelican-plugins to .hgignore

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

mercurial