File: init

package info (click to toggle)
prometheus-pushgateway 0.3.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,272 kB
  • ctags: 333
  • sloc: makefile: 75; sh: 64
file content (70 lines) | stat: -rwxr-xr-x 2,243 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
#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides:          prometheus-pushgateway
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Prometheus exporter for ephemereal jobs
# Description:       The Prometheus Pushgateway exists to allow ephemeral and
#                    batch jobs to expose their metrics to Prometheus. Since
#                    these kinds of jobs may not exist long enough to be
#                    scraped, they can instead push their metrics to a
#                    Pushgateway.  The Pushgateway then exposes these metrics
#                    to Prometheus.
### END INIT INFO

# Author: Martín Ferrari <tincho@debian.org>

DESC="Prometheus exporter for ephemereal jobs"
DAEMON=/usr/bin/prometheus-pushgateway
NAME=prometheus-pushgateway
USER=prometheus
PIDFILE=/var/run/prometheus/prometheus-pushgateway.pid
LOGFILE=/var/log/prometheus/prometheus-pushgateway.log

HELPER=/usr/bin/daemon
HELPER_ARGS="--name=$NAME --output=$LOGFILE --pidfile=$PIDFILE --user=$USER"

ARGS=""
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

do_start_prepare()
{
    mkdir -p `dirname $PIDFILE` || true
    chown -R $USER: `dirname $LOGFILE`
    chown -R $USER: `dirname $PIDFILE`
}

do_start_cmd()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    $HELPER $HELPER_ARGS --running && return 1
    $HELPER $HELPER_ARGS -- $DAEMON $ARGS || return 2
    return 0
}

do_stop_cmd()
{
    # Return
    #   0 if daemon has been stopped
    #   1 if daemon was already stopped
    #   2 if daemon could not be stopped
    #   other if a failure occurred
    $HELPER $HELPER_ARGS --running || return 1
    $HELPER $HELPER_ARGS --stop || return 2
    # wait for the process to really terminate
    for n in 1 2 3 4 5; do
        sleep 1
        $HELPER $HELPER_ARGS --running || break
    done
    $HELPER $HELPER_ARGS --running || return 0
    return 2
}