From e59dd7f0dc005642196d049eac570c28c66ba35e Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Wed, 9 Jan 2019 18:51:27 +0100 Subject: [PATCH] re-instate HEALTHCHECK closes #24 --- Dockerfile | 4 ++++ recorder-health.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 recorder-health.sh diff --git a/Dockerfile b/Dockerfile index 687325c..df2dcce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ MAINTAINER Malte Deiseroth COPY entrypoint.sh /entrypoint.sh COPY config.mk /config.mk COPY recorder.conf /etc/default/recorder.conf +COPY recorder-health.sh /usr/local/sbin/recorder-health.sh ENV VERSION=0.8.0 @@ -25,12 +26,15 @@ RUN apk add --no-cache --virtual .build-deps \ && cd / \ && chmod 755 /entrypoint.sh \ && rm -rf /usr/local/source \ + && chmod 755 /usr/local/sbin/recorder-health.sh \ && apk del .build-deps VOLUME ["/store", "/config"] COPY recorder.conf /config/recorder.conf +HEALTHCHECK CMD /usr/local/sbin/recorder-health.sh + EXPOSE 8083 ENTRYPOINT ["/entrypoint.sh"] diff --git a/recorder-health.sh b/recorder-health.sh new file mode 100644 index 0000000..745dab3 --- /dev/null +++ b/recorder-health.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +addr=`hostname` +port=8083 + +epoch=$(date +%s) + +location=$(cat < /dev/null + +# obtain tst of ping/ping's last location +ret_epoch=$(curl -sSL http://${addr}:${port}/api/0/last --data "user=ping&device=ping" | + env python -c 'import sys, json; print json.load(sys.stdin)[0]["tst"];') + +if [ $epoch -ne $ret_epoch ]; then + echo PANIC $epoch $ret_epoch + exit 1 +else + echo OK + exit 0 +fi