228.1.1
by Marius Kruger
add super cool linux startup script for loggerhead |
1 |
#!/bin/sh
|
2 |
### BEGIN INIT INFO
|
|
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
3 |
# Required-Start: $local_fs $remote_fs $network
|
4 |
# Default-Start: 3 5
|
|
5 |
# Default-Stop: 0 1 2 6
|
|
6 |
# Short-Description: Loggerhead
|
|
7 |
# Description: Manage Loggerhead (a web viewer for projects in bazaar)
|
|
228.1.1
by Marius Kruger
add super cool linux startup script for loggerhead |
8 |
### END INIT INFO
|
9 |
||
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
10 |
|
11 |
#
|
|
12 |
# Configure this please:
|
|
13 |
# (Please stop loggerhead before changing the configuration, otherwise this
|
|
14 |
# script might not be able to kill loggerhead)
|
|
15 |
#
|
|
16 |
||
245.1.1
by Tom Haddon
Allow the script to run as root or another user, but start the loggerhead process as the correct user |
17 |
LHUSER=loggerhead |
18 |
||
19 |
if [ `whoami` = "$LHUSER" ]; then |
|
20 |
SUDO="" |
|
21 |
else
|
|
22 |
SUDO="sudo -H -u $LHUSER" |
|
23 |
fi
|
|
24 |
||
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
25 |
# If serve-branches is not in your path, you will need to specify the full path:
|
26 |
SERVE_BRANCHES_CMD=serve-branches |
|
27 |
||
228.1.1
by Marius Kruger
add super cool linux startup script for loggerhead |
28 |
LOG_FOLDER=/var/log/loggerhead |
29 |
LOG_FILE=$LOG_FOLDER/loggerheadd.log |
|
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
30 |
URL_PREFIX=/loggerhead |
228.1.1
by Marius Kruger
add super cool linux startup script for loggerhead |
31 |
PORT=8080 |
32 |
||
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
33 |
#please specify the base directory to serve:
|
34 |
BZRROOT=/bzrroot |
|
35 |
||
228.1.1
by Marius Kruger
add super cool linux startup script for loggerhead |
36 |
# You can add additional options to serve-branches here:
|
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
37 |
START_CMD="$SERVE_BRANCHES_CMD --prefix=$URL_PREFIX --log-folder=$LOG_FOLDER --port=$PORT $BZRROOT" |
38 |
||
228.1.1
by Marius Kruger
add super cool linux startup script for loggerhead |
39 |
|
40 |
#
|
|
41 |
# main part
|
|
42 |
#
|
|
228.1.5
by Marius Kruger
extract stop and start methods |
43 |
|
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
44 |
loggerhead_process(){
|
245.1.1
by Tom Haddon
Allow the script to run as root or another user, but start the loggerhead process as the correct user |
45 |
$SUDO pgrep -fl "$START_CMD" |
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
46 |
}
|
47 |
||
48 |
loggerhead_status(){
|
|
49 |
proccess=`loggerhead_process` |
|
50 |
#echo "$proccess"
|
|
51 |
listening=`netstat -nl |grep -e ":$PORT "` |
|
52 |
#echo "$listening"
|
|
53 |
if [ -z "$proccess" ]; then |
|
54 |
echo "Loggerhead is *not* running." |
|
55 |
else
|
|
56 |
echo "Loggerhead is running." |
|
57 |
if [ -z "$listening" ]; then |
|
58 |
echo "This server is *not* listening on port $PORT." |
|
59 |
else
|
|
60 |
echo "This server is listening on port $PORT." |
|
61 |
fi
|
|
62 |
fi
|
|
63 |
}
|
|
64 |
||
228.1.5
by Marius Kruger
extract stop and start methods |
65 |
start_loggerhead(){
|
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
66 |
echo "Starting loggerhead. (See $LOG_FOLDER for details.)" |
67 |
||
68 |
# make sure the log folder is created
|
|
245.1.1
by Tom Haddon
Allow the script to run as root or another user, but start the loggerhead process as the correct user |
69 |
if [ ! -d $LOG_FOLDER ] |
70 |
then
|
|
71 |
$SUDO mkdir -p $LOG_FOLDER |
|
72 |
fi
|
|
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
73 |
echo "" > $LOG_FILE |
245.1.1
by Tom Haddon
Allow the script to run as root or another user, but start the loggerhead process as the correct user |
74 |
$SUDO python $START_CMD > $LOG_FILE 2>&1 & |
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
75 |
|
76 |
#wait a little while of some logging to appear
|
|
77 |
log="" |
|
78 |
for i in $(seq 1 3 30); do |
|
79 |
log=`cat $LOG_FILE` |
|
80 |
if [ -n "$log" ]; then |
|
81 |
break
|
|
82 |
fi
|
|
83 |
sleep 0.3
|
|
84 |
done
|
|
85 |
tail $LOG_FILE
|
|
86 |
loggerhead_status |
|
228.1.5
by Marius Kruger
extract stop and start methods |
87 |
}
|
88 |
||
89 |
stop_loggerhead(){
|
|
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
90 |
echo "Stopping loggerhead." |
245.1.1
by Tom Haddon
Allow the script to run as root or another user, but start the loggerhead process as the correct user |
91 |
$SUDO pkill -f "$START_CMD" |
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
92 |
loggerhead_status |
228.1.5
by Marius Kruger
extract stop and start methods |
93 |
}
|
94 |
||
228.1.1
by Marius Kruger
add super cool linux startup script for loggerhead |
95 |
case "$1" in |
96 |
start)
|
|
228.1.5
by Marius Kruger
extract stop and start methods |
97 |
start_loggerhead |
228.1.1
by Marius Kruger
add super cool linux startup script for loggerhead |
98 |
;;
|
99 |
stop)
|
|
228.1.5
by Marius Kruger
extract stop and start methods |
100 |
stop_loggerhead |
228.1.1
by Marius Kruger
add super cool linux startup script for loggerhead |
101 |
;;
|
102 |
status)
|
|
228.1.6
by Marius Kruger
* Change init info tabs->spaces |
103 |
loggerhead_status |
228.1.4
by Marius Kruger
fix whitespace |
104 |
;;
|
228.1.3
by Marius Kruger
add restart |
105 |
restart)
|
228.1.5
by Marius Kruger
extract stop and start methods |
106 |
stop_loggerhead |
107 |
start_loggerhead |
|
228.1.4
by Marius Kruger
fix whitespace |
108 |
;;
|
228.1.1
by Marius Kruger
add super cool linux startup script for loggerhead |
109 |
*)
|
228.1.3
by Marius Kruger
add restart |
110 |
echo "Usage: loggerheadd { start | stop | status | restart }" |
228.1.4
by Marius Kruger
fix whitespace |
111 |
exit 1 |
228.1.1
by Marius Kruger
add super cool linux startup script for loggerhead |
112 |
esac
|