From 99a83f318aff9472b4bc9fde575a82e10dfb78f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kov=C3=A1cs=20Zolt=C3=A1n?= Date: Fri, 22 May 2026 10:45:21 +0200 Subject: [PATCH] feat: Implemented a notification service for unhealthy containers. --- .metadata | Bin 22705 -> 22778 bytes .templates/bin/containermon_redeploy | 74 +++++++++++++++++++++++++++ .templates/bin/watchtower_redeploy | 1 + 3 files changed, 75 insertions(+) create mode 100755 .templates/bin/containermon_redeploy diff --git a/.metadata b/.metadata index 59cbf4c2e1a0c3e1c8d56ee3801ba8067e7f0f69..fa1f92205832aed2ec6b54142e75cdf8d553973d 100644 GIT binary patch delta 152 zcmdnEk@43?#tq9jc=+c0$YcP5!u4d_2kdc_oRN zd8tLY`FWG&q{Vn#_VH$cbcFa;noizmAUY{RW3mIM$>an^!O17JcsC~sUFP7qAu0e? n;r!?oGKp-}<=FLp3R delta 96 zcmeyhk#XZj#tq9jc(P~y$YcP5gDV$^Pi_>@o*cl&KY4=%@8+Kz&p0M;aFCk3L7RVa zfB^62I3amXmdV+-Gbev^GTFRUx?F`PM&K)0^O=h={F4u|=udtiBec2Fp-}<=4+/dev/null) +if [ -z "$TR" ]; then echo "$MSG_MISSINGDEP tr."; exit 1 ; fi +for item in cat dirname docker hostname +do + if [ -n "$(which $item)" ] + then export $(echo $item | "$TR" '[:lower:]' '[:upper:]')=$(which $item) + else echo "$MSG_MISSINGDEP $item." >&2; exit 1; fi +done + +# Stops and removes the container (if necessary). +if [ -n "$("$DOCKER" ps -q -f name=$instance)" ] +then "$DOCKER" stop "$instance"; fi +if [ -n "$("$DOCKER" ps -a -q -f name=$instance)" ] +then "$DOCKER" rm "$instance"; fi + +# Checks for an upgrade. +$DOCKER pull "$image" + +# Creates the container. +$DOCKER create \ + -e TZ="Europe/Budapest" \ + -e CONTAINERMON_CHECK_EXIT_CODE=false \ + -e CONTAINERMON_CHECK_STOPPED=false \ + -e CONTAINERMON_CRON="*/2 * * * *" \ + -e CONTAINERMON_FAIL_LIMIT=1 \ + -e CONTAINERMON_NOTIFICATION_URL="smtp://host.docker.internal:25/?from=$USER@$("$HOSTNAME" -f)&to=$USER@$("$HOSTNAME")&subject=[[Containermon $(hostname)]]" \ + -e CONTAINERMON_HEALTHY_NOTIFICATION_URL="smtp://host.docker.internal:25/?from=$USER@$("$HOSTNAME" -f)&to=$USER@$("$HOSTNAME")&subject=[[Containermon $(hostname)]]" \ + -e CONTAINERMON_NOTIFY_HEALTHY=true \ + -e CONTAINERMON_MESSAGE_PREFIX="" \ + -e CONTAINERMON_USE_LABELS=true \ + -v /var/run/docker.sock:/var/run/docker.sock \ + --add-host="host.docker.internal:host-gateway" \ + --restart unless-stopped \ + --label "com.centurylinklabs.watchtower.enable=true" \ + --name $instance $image + +# Connects it to the network(s). +if [ -n "$networks" ]; then + for network in $networks + do + # Checks the network, creates it if necessary. + if [ -z "$("$DOCKER" network ls -q -f name=$network)" ] + then "$DOCKER" network create -d bridge "$network"; fi + # Then connects. + $DOCKER network connect $network $instance + done +fi + +# Finally launches it. +$DOCKER start $instance +# Adds the time zone handler package to the running container. +$DOCKER exec $instance sh -c "apk add tzdata" +if [ -n "$outfile" -a -w "$("$DIRNAME" "$outfile")" ]; then + # Sets a background process to collect the image's output. + # This process will automatically terminate when the image stops. + "$DOCKER" logs -f $instance >>"$outfile" 2>&1 & +fi diff --git a/.templates/bin/watchtower_redeploy b/.templates/bin/watchtower_redeploy index 10c9015..4cc697f 100755 --- a/.templates/bin/watchtower_redeploy +++ b/.templates/bin/watchtower_redeploy @@ -58,6 +58,7 @@ $DOCKER create \ --add-host="host.docker.internal:host-gateway" \ --restart unless-stopped \ --label "com.centurylinklabs.watchtower.enable=true" \ + --label "containermon.enable=true" \ --name $instance $image # Connects it to the network(s).