aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2016-02-27 18:46:36 +0000
committerChristopher Baines <mail@cbaines.net>2016-02-27 19:14:58 +0000
commit11ecff4f9d0d77fd0f38338dc2f4b830a90097f2 (patch)
treef492556bd2bb54271c87c6c895cbcf124c948124
parentef8a8355e8f402f3843121b07a9c22eee3c400aa (diff)
downloadprometheus-pgbouncer-exporter-11ecff4f9d0d77fd0f38338dc2f4b830a90097f2.tar
prometheus-pgbouncer-exporter-11ecff4f9d0d77fd0f38338dc2f4b830a90097f2.tar.gz
Add a sysvinit script
This requires a dependency on daemon and postgresql-common.
-rw-r--r--debian/control4
-rw-r--r--debian/init66
2 files changed, 70 insertions, 0 deletions
diff --git a/debian/control b/debian/control
index 59e1ef5..4993fcd 100644
--- a/debian/control
+++ b/debian/control
@@ -20,6 +20,10 @@ Package: prometheus-pgbouncer-exporter
Architecture: all
Depends: ${misc:Depends},
${python3:Depends},
+# Depend on postgresql-common, as it creates the postgres user which the init
+# script and service file are configured to run the service as
+ postgresql-common,
+ daemon,
python3-configargparse,
python3-prometheus-client,
python3-psycopg2,
diff --git a/debian/init b/debian/init
new file mode 100644
index 0000000..597bfa0
--- /dev/null
+++ b/debian/init
@@ -0,0 +1,66 @@
+#!/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-pgbouncer-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 pgbouncer
+# Description: Prometheus exporter for pgbouncer metrics, written in
+# Python.
+### END INIT INFO
+
+# Author: Christopher Baines <mail@cbaines.net>
+
+DESC="Prometheus exporter for pgbouncer"
+DAEMON=/usr/bin/prometheus-pgbouncer-exporter
+NAME=prometheus-pgbouncer-exporter
+USER=postgres
+PIDFILE=/var/run/postgresql/prometheus-pgbouncer-exporter.pid
+LOGFILE=/var/log/postgresql/prometheus-pgbouncer-exporter.log
+
+ARGS=""
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+HELPER=/usr/bin/daemon
+HELPER_ARGS="--name=$NAME --output=$LOGFILE --pidfile=$PIDFILE --user=$USER"
+
+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
+}