Debian Codegraph @

debian/init

raw
1 #!/bin/sh
2 # kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
3 if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
4 set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
5 fi
6 ### BEGIN INIT INFO
7 # Provides: prometheus-homeplug-exporter
8 # Required-Start: $remote_fs $syslog
9 # Required-Stop: $remote_fs $syslog
10 # Default-Start: 2 3 4 5
11 # Default-Stop: 0 1 6
12 # Short-Description: Prometheus exporter for HomePlug/Power Line Communication
13 # Description: Exports HomePlug PLC network and station statistics via
14 # HTTP for Prometheus consumption.
15 ### END INIT INFO
16
17 # Author: Martina Ferrari <[email protected]>
18
19 DESC="Prometheus exporter for HomePlug/Power Line Communication"
20 NAME=prometheus-homeplug-exporter
21 DAEMON=/usr/bin/$NAME
22 USER=prometheus
23 PIDFILE=/var/run/prometheus/$NAME.pid
24 LOGFILE=/var/log/prometheus/$NAME.log
25
26 HELPER=/usr/bin/daemon
27 HELPER_ARGS="--name=$NAME --output=$LOGFILE --pidfile=$PIDFILE --user=$USER"
28
29 ARGS=""
30 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
31
32 do_start_prepare()
33 {
34 mkdir -p `dirname $PIDFILE`
35 chown $USER: `dirname $LOGFILE`
36 chown $USER: `dirname $PIDFILE`
37 }
38
39 do_start_cmd_override()
40 {
41 # Return
42 # 0 if daemon has been started or already running
43 # 2 if daemon could not be started
44 $HELPER $HELPER_ARGS --running && return 0
45 $HELPER $HELPER_ARGS -- $DAEMON $ARGS || return 2
46 return 0
47 }
48
49 do_stop_cmd_override()
50 {
51 # Return
52 # 0 if daemon has been stopped or already stopped
53 # 2 if daemon could not be stopped
54 # other if a failure occurred
55 $HELPER $HELPER_ARGS --running || return 0
56 $HELPER $HELPER_ARGS --stop || return 2
57 # wait for the process to really terminate
58 for n in 1 2 3 4 5; do
59 sleep $n
60 $HELPER $HELPER_ARGS --running || break
61 done
62 $HELPER $HELPER_ARGS --running || return 0
63 return 2
64 }