File: rrdcached.init

package info (click to toggle)
rrdtool 1.7.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 5,872 kB
  • sloc: ansic: 38,061; sh: 6,352; perl: 1,240; cs: 652; makefile: 547; python: 140; ruby: 61; awk: 30
file content (191 lines) | stat: -rwxr-xr-x 5,246 bytes parent folder | download | duplicates (6)
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: rrdcached
# Required-Start: $local_fs $remote_fs $named $time $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start or stop rrdcached
# Description: Daemon that accumulates updates to RRD files and flushes
#              them periodically or on command.
### END INIT INFO
#

PATH=/sbin:/usr/sbin:/bin:/usr/bin

NAME=rrdcached
DESC="RRD cache daemon"
DAEMON=/usr/bin/rrdcached

DEFAULT=/etc/default/rrdcached
test -f ${DEFAULT} && . ${DEFAULT}

PIDFILE=${PIDFILE:-/var/run/${NAME}.pid}

RRDCACHED_OPTIONS="\
  ${BASE_OPTIONS} \
  ${NETWORK_OPTIONS} \
  ${WRITE_TIMEOUT:+-w ${WRITE_TIMEOUT}} \
  ${WRITE_JITTER:+-z ${WRITE_JITTER}} \
  ${WRITE_THREADS:+-t ${WRITE_THREADS}} \
  ${BASE_PATH:+-b ${BASE_PATH}} \
  ${JOURNAL_PATH:+-j ${JOURNAL_PATH}} \
  ${DAEMON_GROUP:+-G ${DAEMON_GROUP}} \
  ${DAEMON_USER:+-U ${DAEMON_USER}} \
  -p ${PIDFILE} \
  ${SOCKFILE:+${SOCKGROUP:+-s ${SOCKGROUP}} ${SOCKMODE:+-m ${SOCKMODE}} -l unix:${SOCKFILE}} \
    "

. /lib/lsb/init-functions

RETVAL=1

# Do any pre-start checks.  If this returns nonzero, the failure
# diagnostic has already been generated.
validate_prestart () {
    if [ -n "${JOURNAL_PATH}" -a ! -d "${JOURNAL_PATH}" ] ; then
        mkdir -p "${JOURNAL_PATH}"
        if [ 0 != $? ] ; then
            log_failure_msg "${NAME}: Unable to find/create journal directory ${JOURNAL_PATH}"
            return 1
        fi
    fi
    if [ -n "${BASE_PATH}" -a ! -d "${BASE_PATH}" ] ; then
        mkdir -p "${BASE_PATH}"
        if [ 0 != $? ] ; then
            log_failure_msg "${NAME}: Unable to find/create base directory ${BASE_PATH}"
            return 1
        fi
    fi
    return 0
}

# Whatever's necessary to start a daemon.  Any currently-running
# daemon is left unmolested and no new daemon is started.  Return as
# with start_daemon.
do_start () {
    start_daemon -p ${PIDFILE} ${DAEMON} ${RRDCACHED_OPTIONS}
    return $?
}

# Perform a restart from a state with no daemon running.  This
# function emits the success/failure diagnostics.  Return as with
# restart.
do_restart_diag () {
    validate_prestart
    if [ 0 != $? ] ; then
        rv=$?
    else
        do_start
        rv=$?
        if [ 0 = $? ] ; then
            log_success_msg "${NAME} restarted"
        else
            log_failure_msg "${NAME} restart failed"
        fi
    fi
    return ${rv}
}

# Whatever's necessary to check daemon status.  Sets PID if the daemon
# is running.  Return as pidofproc.
do_status () {
    PID=$( pidofproc -p ${PIDFILE} ${DAEMON} )
    return $?
}

# Whatever's necessary to stop the daemon.  Returns as stop action.
do_stop () {
    killproc -p ${PIDFILE} ${DAEMON}
    rv=$?
    # rrdcached traps the TERM signal and does some flushing.
    # Give it a chance to shut down before returning, lest
    # we restart it too soon.
    max_iters=${STOP_WAIT_DELAY:-5}
    while [ 0 -lt ${max_iters} ] ; do 
        if pidofproc -p ${PIDFILE} ${DAEMON} >/dev/null ; then
            log_warning_msg "${NAME} is still running"
            sleep 1
            max_iters=$(( ${max_iters} - 1 ))
            rv=1
        else
            rv=0
            break
        fi
    done
    return $?
}

case "$1" in
    start)
        # Succeed if service already started or start attempt succeeds
        if do_status > /dev/null ; then
            log_success_msg "${NAME} is already started as ${PID}"
            RETVAL=0
        else
            validate_prestart
            RETVAL=$?
            if [ 0 = ${RETVAL} ] ; then
                do_start
                RETVAL=$?
                if [ 0 = ${RETVAL} ] ; then
                    log_success_msg "${NAME} started"
                else
                    log_failure_msg "${NAME} FAILED"
                fi
            fi
        fi
        ;;
    stop)
        if pidofproc -p ${PIDFILE} ${DAEMON} > /dev/null ; then
            do_stop
            RETVAL=$?
            if [ 0 = ${RETVAL} ] ; then
                log_success_msg "${NAME} has been stopped"
            else
                log_failure_msg "${NAME} was not stopped"
            fi
        else
            log_success_msg "${NAME} was already stopped"
            RETVAL=0
        fi
        ;;
    restart)
        do_stop
        do_restart_diag
        RETVAL=$?
        ;;
    try-restart)
        if pidofproc -p ${PIDFILE} ${DAEMON} > /dev/null ; then
            do_stop
            do_restart_diag
            RETVAL=$?
        else
            # Yes, try-restart when the system is not running is
            # success.
            log_success_msg "${NAME} not running"
            RETVAL=0
        fi
        ;;
    reload|force-reload)
        RETVAL=3
        log_failure_msg "${NAME} does not support $1"
        ;;
    status)
        do_status
        RETVAL=$?
        if [ 0 = "${RETVAL}" ] ; then
            log_success_msg "${NAME} status ${RETVAL} is running as ${PID}"
        else
            log_failure_msg "${NAME} is not running"
        fi
        ;;
    '')
        log_warning_msg "No command (try: status)"
        ;;
    *)
        log_warning_msg "Unrecognized command: $1"
        ;;
esac

exit $RETVAL