From b82721ab6a935cc52c463f2baa407819e3a6047c Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 21 May 2023 10:47:05 +0200 Subject: [PATCH] test --- portainer_agent/Dockerfile | 12 ++++------- portainer_agent/config.json | 4 ++-- portainer_agent/rootfs/entrypoint.sh | 16 -------------- portainer_agent/rootfs/usr/sbin/healthcheck | 7 +++++++ .../rootfs/usr/sbin/wait-for-signal | 21 +++++++++++++++++++ 5 files changed, 34 insertions(+), 26 deletions(-) delete mode 100755 portainer_agent/rootfs/entrypoint.sh create mode 100644 portainer_agent/rootfs/usr/sbin/healthcheck create mode 100644 portainer_agent/rootfs/usr/sbin/wait-for-signal diff --git a/portainer_agent/Dockerfile b/portainer_agent/Dockerfile index 1de50846f..74686a69d 100644 --- a/portainer_agent/Dockerfile +++ b/portainer_agent/Dockerfile @@ -75,6 +75,9 @@ RUN if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get # 4 Entrypoint # ################ +RUN chmod a+x /usr/sbin/healthcheck && \ + chmod a+x /usr/sbin/wait-for-signal + WORKDIR [ "/app" ] ENTRYPOINT [ "/init" ] @@ -112,11 +115,4 @@ LABEL \ # 6 Healthcheck # ################# -ENV HEALTH_PORT="9000" \ - HEALTH_URL="/api/system/status" -HEALTHCHECK \ - --interval=5s \ - --retries=5 \ - --start-period=30s \ - --timeout=25s \ - CMD curl --fail "http://127.0.0.1:${HEALTH_PORT}${HEALTH_URL}" &>/dev/null || exit 1 +HEALTHCHECK --interval=10s --timeout=5s --retries=3 CMD healthcheck diff --git a/portainer_agent/config.json b/portainer_agent/config.json index 410a39768..d9425fa01 100644 --- a/portainer_agent/config.json +++ b/portainer_agent/config.json @@ -44,5 +44,5 @@ }, "slug": "portainer_agent", "url": "https://github.com/alexbelgium/hassio-addons", - "version": "2.18.2-test4" -} + "version": "2.18.2-test5" +} \ No newline at end of file diff --git a/portainer_agent/rootfs/entrypoint.sh b/portainer_agent/rootfs/entrypoint.sh deleted file mode 100755 index 68c3fec4d..000000000 --- a/portainer_agent/rootfs/entrypoint.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -echo "Starting..." - -#################### -# Starting scripts # -#################### - -for SCRIPTS in /etc/cont-init.d/*; do - [ -e "$SCRIPTS" ] || continue - echo "$SCRIPTS: executing" - chown "$(id -u)":"$(id -g)" "$SCRIPTS" - chmod a+x "$SCRIPTS" - # Change shebang if no s6 supervision - sed -i 's|/usr/bin/with-contenv bashio|/usr/bin/env bashio|g' "$SCRIPTS" - /."$SCRIPTS" || echo "$SCRIPTS: exiting $?" -done diff --git a/portainer_agent/rootfs/usr/sbin/healthcheck b/portainer_agent/rootfs/usr/sbin/healthcheck new file mode 100644 index 000000000..7fb607a38 --- /dev/null +++ b/portainer_agent/rootfs/usr/sbin/healthcheck @@ -0,0 +1,7 @@ +#!/usr/bin/with-contenv bash + +if [ -f "/tmp/healthcheck-signal" ]; then + curl -k --fail https://127.0.0.1:9001/ping || exit 1 +else + touch /tmp/healthcheck-signal +fi \ No newline at end of file diff --git a/portainer_agent/rootfs/usr/sbin/wait-for-signal b/portainer_agent/rootfs/usr/sbin/wait-for-signal new file mode 100644 index 000000000..8be4066ee --- /dev/null +++ b/portainer_agent/rootfs/usr/sbin/wait-for-signal @@ -0,0 +1,21 @@ +#!/usr/bin/with-contenv bashio + +START_TIME=`date +%s` + +echo "Waiting for first healthcheck execution (max $FIRST_HEALTHCHECK_TIMEOUT seconds)..." + +while [ ! -f "/tmp/healthcheck-signal" ]; +do + sleep 1 + + ELAPSED_TIME=`expr \`date +%s\` - $START_TIME` + + if [ $ELAPSED_TIME -gt $FIRST_HEALTHCHECK_TIMEOUT ] + then + echo "Signal from healthcheck not received in time, failing the execution..." + exit 20 + fi +done + +echo "Signal from healthcheck received" +exit 0 \ No newline at end of file