~loggerhead-team/loggerhead/trunk-rich

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
17
# If serve-branches is not in your path, you will need to specify the full path:
18
SERVE_BRANCHES_CMD=serve-branches
19
228.1.1 by Marius Kruger
add super cool linux startup script for loggerhead
20
LOG_FOLDER=/var/log/loggerhead
21
LOG_FILE=$LOG_FOLDER/loggerheadd.log
228.1.6 by Marius Kruger
* Change init info tabs->spaces
22
URL_PREFIX=/loggerhead
228.1.1 by Marius Kruger
add super cool linux startup script for loggerhead
23
PORT=8080
24
228.1.6 by Marius Kruger
* Change init info tabs->spaces
25
#please specify the base directory to serve:
26
BZRROOT=/bzrroot
27
228.1.1 by Marius Kruger
add super cool linux startup script for loggerhead
28
# You can add additional options to serve-branches here:
228.1.6 by Marius Kruger
* Change init info tabs->spaces
29
START_CMD="$SERVE_BRANCHES_CMD --prefix=$URL_PREFIX --log-folder=$LOG_FOLDER --port=$PORT $BZRROOT"
30
228.1.1 by Marius Kruger
add super cool linux startup script for loggerhead
31
32
#
33
# main part
34
#
228.1.5 by Marius Kruger
extract stop and start methods
35
228.1.6 by Marius Kruger
* Change init info tabs->spaces
36
loggerhead_process(){
37
    pgrep -fl "$START_CMD"
38
}
39
40
loggerhead_status(){
41
    proccess=`loggerhead_process`
42
    #echo "$proccess"
43
    listening=`netstat -nl |grep -e ":$PORT "`
44
    #echo "$listening"
45
    if [ -z "$proccess" ]; then
46
        echo "Loggerhead is *not* running."
47
    else
48
        echo "Loggerhead is running."
49
        if [ -z "$listening" ]; then
50
            echo "This server is *not* listening on port $PORT."
51
        else
52
            echo "This server is listening on port $PORT."
53
        fi
54
    fi
55
}
56
228.1.5 by Marius Kruger
extract stop and start methods
57
start_loggerhead(){
228.1.6 by Marius Kruger
* Change init info tabs->spaces
58
    echo "Starting loggerhead.   (See $LOG_FOLDER for details.)"
59
60
    # make sure the log folder is created
61
    mkdir -p $LOG_FOLDER
62
    echo "" > $LOG_FILE
228.1.5 by Marius Kruger
extract stop and start methods
63
    python $START_CMD > $LOG_FILE 2>&1 &
228.1.6 by Marius Kruger
* Change init info tabs->spaces
64
65
    #wait a little while of some logging to appear
66
    log=""
67
    for i in $(seq 1 3 30); do
68
        log=`cat $LOG_FILE`
69
        if [ -n "$log" ]; then
70
            break
71
        fi
72
        sleep 0.3
73
    done
74
    tail $LOG_FILE
75
    loggerhead_status
228.1.5 by Marius Kruger
extract stop and start methods
76
}
77
78
stop_loggerhead(){
228.1.6 by Marius Kruger
* Change init info tabs->spaces
79
    echo "Stopping loggerhead."
228.1.5 by Marius Kruger
extract stop and start methods
80
    pkill -f "$START_CMD"
228.1.6 by Marius Kruger
* Change init info tabs->spaces
81
    loggerhead_status
228.1.5 by Marius Kruger
extract stop and start methods
82
}
83
228.1.1 by Marius Kruger
add super cool linux startup script for loggerhead
84
case "$1" in
85
    start)
228.1.5 by Marius Kruger
extract stop and start methods
86
        start_loggerhead
228.1.1 by Marius Kruger
add super cool linux startup script for loggerhead
87
    ;;
88
    stop)
228.1.5 by Marius Kruger
extract stop and start methods
89
        stop_loggerhead
228.1.1 by Marius Kruger
add super cool linux startup script for loggerhead
90
    ;;
91
    status)
228.1.6 by Marius Kruger
* Change init info tabs->spaces
92
        loggerhead_status
228.1.4 by Marius Kruger
fix whitespace
93
    ;;
228.1.3 by Marius Kruger
add restart
94
    restart)
228.1.5 by Marius Kruger
extract stop and start methods
95
        stop_loggerhead
96
        start_loggerhead
228.1.4 by Marius Kruger
fix whitespace
97
    ;;
228.1.1 by Marius Kruger
add super cool linux startup script for loggerhead
98
    *)
228.1.3 by Marius Kruger
add restart
99
        echo "Usage: loggerheadd { start | stop | status | restart }"
228.1.4 by Marius Kruger
fix whitespace
100
        exit 1
228.1.1 by Marius Kruger
add super cool linux startup script for loggerhead
101
esac