From 1d52a49f5c8158b1336f8271a6ea8afb39396d07 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Wed, 29 Nov 2023 23:57:04 +0100 Subject: [PATCH] Implement a service to notify about failures with an email. --- notify_failure@.service | 16 ++++++++++++++++ notify_on_failure.sh | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 notify_failure@.service create mode 100755 notify_on_failure.sh diff --git a/notify_failure@.service b/notify_failure@.service new file mode 100644 index 0000000..4a67097 --- /dev/null +++ b/notify_failure@.service @@ -0,0 +1,16 @@ +# Copyright (c) 2023 Jakub Czajka +# License: GPL-3.0 or later. + +[Unit] +Description=Notify about failure through an email notification. + +[Service] +Type=oneshot +ExecStartPre=/usr/bin/git \ + --work-tree=/tmp \ + --git-dir=/srv/git/cron.git \ + checkout main --force notify_on_failure.sh +ExecStart=/tmp/notify_on_failure.sh %I + +[Install] +WantedBy=multi-user.target diff --git a/notify_on_failure.sh b/notify_on_failure.sh new file mode 100755 index 0000000..2043dc7 --- /dev/null +++ b/notify_on_failure.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# Copyright (c) 2023 Jakub Czajka +# License: GPL-3.0 or later. + +MAILTO="server@${private_domain}" +MAILFROM="server@${private_domain}" +UNIT=${1} + +/usr/sbin/sendmail ${MAILTO} <