~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerheadd

  • Committer: Martin Albisetti
  • Date: 2008-11-17 02:13:23 UTC
  • mfrom: (228.1.6 loggerheadd)
  • Revision ID: martin.albisetti@canonical.com-20081117021323-r1d2ilvrvuzxm6t2
Add startup script for linux (Marius Kruger)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
### BEGIN INIT INFO
 
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)
 
8
### END INIT INFO
 
9
 
 
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
 
 
20
LOG_FOLDER=/var/log/loggerhead
 
21
LOG_FILE=$LOG_FOLDER/loggerheadd.log
 
22
URL_PREFIX=/loggerhead
 
23
PORT=8080
 
24
 
 
25
#please specify the base directory to serve:
 
26
BZRROOT=/bzrroot
 
27
 
 
28
# You can add additional options to serve-branches here:
 
29
START_CMD="$SERVE_BRANCHES_CMD --prefix=$URL_PREFIX --log-folder=$LOG_FOLDER --port=$PORT $BZRROOT"
 
30
 
 
31
 
 
32
#
 
33
# main part
 
34
#
 
35
 
 
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
 
 
57
start_loggerhead(){
 
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
 
63
    python $START_CMD > $LOG_FILE 2>&1 &
 
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
 
76
}
 
77
 
 
78
stop_loggerhead(){
 
79
    echo "Stopping loggerhead."
 
80
    pkill -f "$START_CMD"
 
81
    loggerhead_status
 
82
}
 
83
 
 
84
case "$1" in
 
85
    start)
 
86
        start_loggerhead
 
87
    ;;
 
88
    stop)
 
89
        stop_loggerhead
 
90
    ;;
 
91
    status)
 
92
        loggerhead_status
 
93
    ;;
 
94
    restart)
 
95
        stop_loggerhead
 
96
        start_loggerhead
 
97
    ;;
 
98
    *)
 
99
        echo "Usage: loggerheadd { start | stop | status | restart }"
 
100
        exit 1
 
101
esac