-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevelop_server.sh
More file actions
executable file
·113 lines (100 loc) · 2.59 KB
/
develop_server.sh
File metadata and controls
executable file
·113 lines (100 loc) · 2.59 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/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
source "$BASEDIR/pythonenv/bin/activate"
###
# Don't change stuff below here unless you are sure
#
# Nate hacked this so that he can have Chrome auto-refresh any dev environment
# tabs in the background whenever he makes a change to the content/ directory.
###
SRV_PID=$BASEDIR/srv.pid
PELICAN_PID=$BASEDIR/pelican.pid
CHROMEWATCH_PID=$BASEDIR/chromewatch.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
if [[ -f $CHROMEWATCH_PID ]]; then
PID=$(cat $CHROMEWATCH_PID)
PROCESS=$(ps -p $PID | tail -n 1 | awk '{print $4}')
if [[ $PROCESS != "" ]]; then
echo "Killing chromewatch"
kill $PID
else
echo "Stale PID, deleting"
fi
rm $CHROMEWATCH_PID
else
echo "chromewatch 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 SimpleHTTPServer 7999 &
echo $! > $SRV_PID
cd $BASEDIR
# The Chrome-watching script depends on fswatch, so only run it if it's
# installed.
if command -v fswatch; then
"$BASEDIR/chrome-watcher.sh" &
echo $! > $CHROMEWATCH_PID
fi
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