71 lines
2.1 KiB
Bash
71 lines
2.1 KiB
Bash
#!/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-postgres-exporter
|
|
# 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 machine metrics
|
|
# Description: Prometheus exporter for machine metrics, written in Go
|
|
# with pluggable metric collectors.
|
|
### END INIT INFO
|
|
|
|
# Author: Martina Ferrari <tincho@debian.org>
|
|
|
|
DESC="Prometheus exporter for PostgreSQL metrics"
|
|
DAEMON=/usr/bin/prometheus-postgres-exporter
|
|
NAME=prometheus-postgres-exporter
|
|
USER=prometheus
|
|
PIDFILE=/var/run/prometheus/prometheus-postgres-exporter.pid
|
|
LOGFILE=/var/log/prometheus/prometheus-postgres-exporter.log
|
|
|
|
ARGS=""
|
|
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
|
|
|
|
HELPER=/usr/bin/daemon
|
|
HELPER_ARGS="--name=$NAME --output=$LOGFILE --pidfile=$PIDFILE --user=$USER
|
|
--inherit"
|
|
|
|
do_start_prepare()
|
|
{
|
|
mkdir -p `dirname $PIDFILE`
|
|
chown $USER: `dirname $LOGFILE`
|
|
chown $USER: `dirname $PIDFILE`
|
|
if test -z "$DATA_SOURCE_NAME"; then
|
|
log_failure_msg \
|
|
"missing \$DATA_SOURCE_NAME -- please edit /etc/default/$NAME"
|
|
exit
|
|
fi
|
|
}
|
|
|
|
do_start_cmd_override()
|
|
{
|
|
# Return
|
|
# 0 if daemon has been started or already running
|
|
# 2 if daemon could not be started
|
|
$HELPER $HELPER_ARGS --running && return 0
|
|
$HELPER $HELPER_ARGS -- $DAEMON $ARGS || return 2
|
|
return 0
|
|
}
|
|
|
|
do_stop_cmd_override()
|
|
{
|
|
# Return
|
|
# 0 if daemon has been stopped or already stopped
|
|
# 2 if daemon could not be stopped
|
|
# other if a failure occurred
|
|
$HELPER $HELPER_ARGS --running || return 0
|
|
$HELPER $HELPER_ARGS --stop || return 2
|
|
# wait for the process to really terminate
|
|
for n in 1 2 3 4 5; do
|
|
sleep $n
|
|
$HELPER $HELPER_ARGS --running || break
|
|
done
|
|
$HELPER $HELPER_ARGS --running || return 0
|
|
return 2
|
|
}
|