~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerheadd

  • Committer: Marius Kruger
  • Date: 2008-10-14 12:16:22 UTC
  • mto: This revision was merged to the branch mainline in revision 240.
  • Revision ID: amanic@gmail.com-20081014121622-nfogplfxss2k3lac
extract stop and start methods

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
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)
 
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
8
### END INIT INFO
9
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
 
LHUSER=loggerhead
18
 
 
19
 
if [ `whoami` = "$LHUSER" ]; then                                                                                   
20
 
    SUDO=""
21
 
else                                                                                                                
22
 
    SUDO="sudo -H -u $LHUSER"
23
 
fi
24
 
 
25
 
# If serve-branches is not in your path, you will need to specify the full path:
26
 
SERVE_BRANCHES_CMD=serve-branches
27
 
 
 
10
# Configure this please: #
 
11
LOGGERHEAD_PATH=/opt/loggerhead
28
12
LOG_FOLDER=/var/log/loggerhead
29
13
LOG_FILE=$LOG_FOLDER/loggerheadd.log
30
 
URL_PREFIX=/loggerhead
 
14
PREFIX=/loggerhead
31
15
PORT=8080
32
16
 
33
 
#please specify the base directory to serve:
34
 
BZRROOT=/bzrroot
35
 
 
36
17
# You can add additional options to serve-branches here:
37
 
START_CMD="$SERVE_BRANCHES_CMD --prefix=$URL_PREFIX --log-folder=$LOG_FOLDER --port=$PORT $BZRROOT"
38
 
 
 
18
START_CMD="$LOGGERHEAD_PATH/serve-branches --prefix=$PREFIX --log-folder=$LOG_FOLDER --port=$PORT /var/lib/gforge/bzrroot/"
39
19
 
40
20
#
41
21
# main part
42
22
#
43
23
 
44
 
loggerhead_process(){
45
 
    $SUDO pgrep -fl "$START_CMD"
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
 
 
65
24
start_loggerhead(){
66
 
    echo "Starting loggerhead.   (See $LOG_FOLDER for details.)"
67
 
 
68
 
    # make sure the log folder is created
69
 
    if [ ! -d $LOG_FOLDER ]
70
 
    then
71
 
        $SUDO mkdir -p $LOG_FOLDER
72
 
    fi
73
 
    echo "" > $LOG_FILE
74
 
    $SUDO python $START_CMD > $LOG_FILE 2>&1 &
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
 
25
    python $START_CMD > $LOG_FILE 2>&1 &
 
26
    echo "Started loggerhead.   (See $LOG_FOLDER for details.)"
87
27
}
88
28
 
89
29
stop_loggerhead(){
90
 
    echo "Stopping loggerhead."
91
 
    $SUDO pkill -f "$START_CMD"
92
 
    loggerhead_status
 
30
    pkill -f "$START_CMD"
 
31
    proccess=`pgrep -fl "$START_CMD"`
 
32
    if [ -z "$proccess" ]; then
 
33
        echo "Loggerhead was stopped."
 
34
    fi
93
35
}
94
36
 
95
37
case "$1" in
100
42
        stop_loggerhead
101
43
    ;;
102
44
    status)
103
 
        loggerhead_status
 
45
        proccess=`pgrep -fl "$START_CMD"`
 
46
        echo "$proccess"
 
47
        netstat -anp |grep -e ":$PORT"
 
48
        if [ -z "$proccess" ]; then
 
49
            echo "Loggerhead is not running."
 
50
        else
 
51
            echo "Loggerhead is running."
 
52
        fi
104
53
    ;;
105
54
    restart)
106
55
        stop_loggerhead