geminispace.info

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/geminispace.info.git
Log | Files | Refs | README | LICENSE

commit 409d9c14076a70495484ee9df304afa31c8132f8
parent c837404b0474e5b3ae35cef75859d33bec3ff3fe
Author: Remco <me@rwv.io>
Date:   Tue, 22 Dec 2020 12:46:04 +0100

Health test script and systemd service

Just for reference, it's already running elsewhere.

Signed-off-by: Natalie Pendragon <natpen@natpen.net>

Diffstat:
Ainfra/gemini-health-check | 37+++++++++++++++++++++++++++++++++++++
Ainfra/gemini-health-check-gus.guru.service | 12++++++++++++
2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/infra/gemini-health-check b/infra/gemini-health-check @@ -0,0 +1,37 @@ +#!/bin/sh + +set -e + +if [ -z "$1" ] || [ -z "$2" ]; then + echo "Usage: $0 EMAIL HOSTNAME [PORT] [URL]" + exit 1 +fi + +EMAIL="$1" +HOSTNAME="$2" +PORT="$3" +URL="$4" + +[ -z "$PORT" ] && PORT=1965 +[ -z "$URL" ] && URL="gemini://$HOSTNAME:$PORT/" +[ -z "$FROM_EMAIL" ] && FROM_EMAIL="noreply@$(hostname)" + +PREVIOUS_STATE="/var/lib/gemini-health-check/$HOSTNAME" +CURRENT_STATE="/var/lib/gemini-health-check/$HOSTNAME.$$" + +echo "$URL\r" \ +| openssl s_client -servername "$HOSTNAME" -connect "$HOSTNAME:$PORT" -quiet 2>&1 \ +| sed -E -e 's,^[0-9]{10\,}:error:,,' \ +> "$CURRENT_STATE" + +if cmp "$PREVIOUS_STATE" "$CURRENT_STATE" > /dev/null 2>&1; then + : +else + ( + echo "Current response from $URL:" + echo + sed 's,^,> ,' < "$CURRENT_STATE" + ) | mail -r "$FROM_EMAIL" -s "$HOSTNAME status changed" "$EMAIL" +fi + +mv "$CURRENT_STATE" "$PREVIOUS_STATE" diff --git a/infra/gemini-health-check-gus.guru.service b/infra/gemini-health-check-gus.guru.service @@ -0,0 +1,12 @@ +[Unit] +Description=Gemini Health Check: gus.guru +Wants=network-online.target + +[Service] +User=daemon +ExecStart=/usr/local/bin/gemini-health-check ~natpen/gus@lists.sr.ht gus.guru 1965 gemini://gus.guru/status +Restart=always +RestartSec=5min + +[Install] +WantedBy=multi-user.target