-
Notifications
You must be signed in to change notification settings - Fork 3
/
develop_server.sh
executable file
·84 lines (76 loc) · 1.82 KB
/
develop_server.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
##
# This section should match your Makefile
##
PELICAN=pelican
PELICANOPTS=
BASEDIR=$(pwd)
INPUTDIR=$BASEDIR/content
OUTPUTDIR=$BASEDIR/output
CONFFILE=$BASEDIR/pelicanconf.py
###
# Don't change stuff below here unless you are sure
###
SRV_PID=$BASEDIR/srv.pid
PELICAN_PID=$BASEDIR/pelican.pid
function usage(){
echo "usage: $0 (stop) (start) (restart)"
echo "This starts pelican in debug and reload mode and then launches"
echo "A SimpleHTTP server to help site development. It doesn't read"
echo "your pelican options so you edit any paths in your Makefile"
echo "you will need to edit it as well"
exit 3
}
function shut_down(){
if [[ -f $SRV_PID ]]; then
PID=$(cat $SRV_PID)
PROCESS=$(ps -p $PID | tail -n 1 | awk '{print $4}')
if [[ $PROCESS != "" ]]; then
echo "Killing SimpleHTTPServer"
kill $PID
else
echo "Stale PID, deleting"
fi
rm $SRV_PID
else
echo "SimpleHTTPServer PIDFile not found"
fi
if [[ -f $PELICAN_PID ]]; then
PID=$(cat $PELICAN_PID)
PROCESS=$(ps -p $PID | tail -n 1 | awk '{print $4}')
if [[ $PROCESS != "" ]]; then
echo "Killing Pelican"
kill $PID
else
echo "Stale PID, deleting"
fi
rm $PELICAN_PID
else
echo "Pelican PIDFile not found"
fi
}
function start_up(){
echo "Starting up Pelican and SimpleHTTPServer"
shift
$PELICAN --debug --autoreload -r $INPUTDIR -o $OUTPUTDIR -s $CONFFILE $PELICANOPTS &
echo $! > $PELICAN_PID
cd $OUTPUTDIR
python -m http.server &
echo $! > $SRV_PID
cd $BASEDIR
sleep 1 && echo 'Pelican and SimpleHTTPServer processes now running in background.'
}
###
# MAIN
###
[[ $# -ne 1 ]] && usage
if [[ $1 == "stop" ]]; then
shut_down
elif [[ $1 == "restart" ]]; then
shut_down
start_up
elif [[ $1 == "start" ]]; then
start_up
else
usage
fi