File: init.d

package info (click to toggle)
smokeping 2.3.6-5%2Bsqueeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 3,964 kB
  • ctags: 2,378
  • sloc: perl: 14,815; sh: 523; makefile: 242
file content (199 lines) | stat: -rw-r--r-- 4,937 bytes parent folder | download | duplicates (3)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/sh
#
# /etc/init.d/smokeping
#
### BEGIN INIT INFO
# Provides:          smokeping
# Required-Start:    $syslog $network
# Should-Start:      sshd apache
# Required-Stop:     $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start or stop the smokeping latency logging system daemon
# Description:       SmokePing is a latency logging and graphing system
#                    that consists of a daemon process which organizes 
#                    the latency measurements and a CGI which presents 
#                    the graphs. This script is used to start or stop
#                    the daemon.
### END INIT INFO
# 

set -e

# Source LSB init functions
. /lib/lsb/init-functions

DAEMON=/usr/sbin/smokeping
NAME=smokeping
DESC="latency logger daemon"
CONFIG=/etc/smokeping/config
PIDFILE=/var/run/smokeping/$NAME.pid
DAEMON_USER=smokeping
DEFAULTS=/etc/default/smokeping
MODE=master
DAEMON_ARGS=""

# LC_ALL prevents resetting LC_NUMERIC which in turn interferes
# with Smokeping internal regexps matching floating point numbers
unset LC_ALL

# Check whether the binary is still present:
test -f "$DAEMON" || exit 0

# source defaults for master vs. slave mode
if [ -f "$DEFAULTS" ]
then
    . "$DEFAULTS"
fi

check_slave() {
    if [ "$MODE" != "slave" ]
    then
        return
    fi
    if [ -z "$SHARED_SECRET" ]
    then
        log_progress_msg "(missing \$SHARED_SECRET setting)"
        log_end_msg 6 # program is not configured
        exit 6
    fi
    if [ ! -r "$SHARED_SECRET" ]
    then
        log_progress_msg "(invalid \$SHARED_SECRET setting)"
        log_end_msg 2 # invalid or excess argument(s)
        exit 2
    fi
    if [ -z "$MASTER_URL" ]
    then
        log_progress_msg "(missing \$MASTER_URL setting)"
        log_end_msg 6 # program is not configured
        exit 6
    fi
    DAEMON_ARGS="$DAEMON_ARGS --master-url $MASTER_URL --shared-secret $SHARED_SECRET"
    if [ -n "$SLAVE_NAME" ]
    then
        DAEMON_ARGS="$DAEMON_ARGS --slave-name $SLAVE_NAME"
    fi
    DAEMON_ARGS="$DAEMON_ARGS --cache-dir /var/lib/smokeping"
    DAEMON_ARGS="$DAEMON_ARGS --pid-dir /var/run/smokeping"
}

check_config () {
    # Check whether the configuration file is available
    if [ ! -r "$CONFIG" ] && [ "$MODE" = "master" ]
    then
        log_progress_msg "($CONFIG does not exist)"
        log_end_msg 6 # program is not configured
        exit 6
    fi
}

case "$1" in
    start)
    log_daemon_msg "Starting $DESC" $NAME
    check_config
    check_slave
    set +e
    pidofproc "$DAEMON" > /dev/null
    STATUS=$?
    set -e
    if [ "$STATUS" = 0 ]
    then
        log_progress_msg "already running"
        log_end_msg $STATUS
        exit $STATUS
    fi

    if [ ! -d /var/run/smokeping ]; then
        mkdir /var/run/smokeping
        chown ${DAEMON_USER}.root /var/run/smokeping
        chmod 0755 /var/run/smokeping
    fi

    set +e
    start-stop-daemon --start --quiet --exec $DAEMON --oknodo \
                            --chuid $DAEMON_USER --pidfile $PIDFILE \
                            -- $DAEMON_ARGS \
                            | logger -p daemon.notice -t $NAME
    STATUS=$?
    set -e

    log_end_msg $STATUS
    exit $STATUS
    ;;


    stop)
    log_daemon_msg "Shutting down $DESC" $NAME

    set +e
    start-stop-daemon --oknodo --stop --retry 3 --quiet --pidfile /var/run/smokeping/$NAME.pid --signal 15
    STATUS=$?
    set -e

    if [ "$STATUS" = 0 ]
    then
        rm -f $PIDFILE
	pkill -u www-data speedy_backend || true
    fi

    log_end_msg $STATUS
    exit $STATUS
    ;;


    restart)
    # Restart service (if running) or start service
    $0 stop
    $0 start
    ;;


    reload|force-reload)
    log_action_begin_msg "Reloading $DESC configuration" 

    check_config
    set +e
    $DAEMON --reload | logger -p daemon.notice -t smokeping
    STATUS=$?
    set -e

    if [ "$STATUS" = 0 ]
    then
        log_action_end_msg 0 "If the CGI has problems reloading, see README.Debian."
    else
        log_action_end_msg $STATUS
    fi
    exit $STATUS
    ;;


    status)
    log_daemon_msg "Checking $DESC status" $NAME
    # Use pidofproc to check the status of the service,
    # pidofproc returns the exit status code of 0 when it the process is
    # running.

    # LSB defined exit status codes for status:
    # 0    program is running or service is OK
    # 1    program is dead and /var/run pid file exists
    # 2    program is dead and /var/lock lock file exists
    # 3    program is not running
    # 4    program or service status is unknown
    # 5-199    reserved (5-99 LSB, 100-149 distribution, 150-199 applications)
    
    set +e
    pidofproc "$DAEMON" > /dev/null
    STATUS=$?
    log_progress_msg "(status $STATUS)"
    log_end_msg 0
    set -e
    exit $STATUS
    ;;


    *)
    echo "Usage: $0 {start|stop|status|restart|force-reload|reload}"
    exit 1
    ;;
esac