From 34ac360bfcaf92bb07564d3b807b507b8aad9426 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 9 Sep 2020 15:52:56 -0300 Subject: [PATCH] actually work --- Dockerfile | 1 + monit.conf | 4 ++++ prometheusd.sh | 23 +++++++++++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 monit.conf diff --git a/Dockerfile b/Dockerfile index 9aa7cdf..488e854 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM sutty/monit:latest MAINTAINER "f " RUN apk add --no-cache prometheus daemonize +COPY ./monit.conf /etc/monit.d/prometheus.conf COPY ./prometheusd.sh /usr/local/bin/prometheusd EXPOSE 9090 diff --git a/monit.conf b/monit.conf new file mode 100644 index 0000000..b956685 --- /dev/null +++ b/monit.conf @@ -0,0 +1,4 @@ +check process postfix with pidfile /var/spool/postfix/pid/master.pid + start program = "/usr/local/bin/prometheusd start" + stop program = "/usr/local/bin/prometheusd stop" + if 5 restarts within 8 cycles then alert diff --git a/prometheusd.sh b/prometheusd.sh index c5ccb17..ff8e549 100755 --- a/prometheusd.sh +++ b/prometheusd.sh @@ -2,9 +2,24 @@ pid=/tmp/prometheus.pid var=/var/lib/prometheus -log=/dev/log -chown prometheus:prometheus /var/lib/prometheus/data +case $1 in + stop) + test -f "${pid}" || exit 0 -daemonize -p "${pid}" -l "${pid}" -u prometheus -c "${var}" -a -o "${log}" -e "${log}" \ - /usr/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path="${var}/data" + cat "${pid}" | xargs -r kill + + rm "${pid}" + ;; + start) + rm -f "${pid}" + + chown prometheus:prometheus /var/lib/prometheus/data + chmod -R u=rwX,g=rX,o= /var/lib/prometheus + + daemonize -p "${pid}" -l "${pid}" -u prometheus -c "${var}" \ + /usr/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path="${var}/data" + ;; +esac + +exit $?