From d76ee333cc20c12eed32426f9756be024eae62c0 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Tue, 19 Jun 2018 17:12:10 +1000 Subject: [PATCH 1/1] Initial commit --- PKGBUILD | 18 ++++++++++++++++++ makedeb | 34 ++++++++++++++++++++++++++++++++++ systemd-monitor | 15 +++++++++++++++ systemd-monitor.service | 8 ++++++++ 4 files changed, 75 insertions(+) create mode 100644 PKGBUILD create mode 100755 makedeb create mode 100755 systemd-monitor create mode 100644 systemd-monitor.service diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..2db752b --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,18 @@ +pkgbase="systemd-monitor" +pkgname="systemd-monitor" +pkgdesc="Monitor systemd state and email root if there is a problem" +pkgver=1.0.0 +pkgrel=1 +arch=("any") +source=("systemd-monitor" + "systemd-monitor.service") +md5sums=('956a73156e7edfdfc925aea2e7ed76ad' + 'bca0d235b9babc7ce5289fa5579f3d88') + +package() { + mkdir -p "${pkgdir}/usr/bin/" + install -m 0755 systemd-monitor "${pkgdir}/usr/bin/" + + mkdir -p "${pkgdir}/usr/lib/systemd/system/" + install -m 0644 systemd-monitor.service "${pkgdir}/usr/lib/systemd/system/" +} diff --git a/makedeb b/makedeb new file mode 100755 index 0000000..4129f19 --- /dev/null +++ b/makedeb @@ -0,0 +1,34 @@ +#!/bin/bash + +set -eu + +if [ "$(id -u)" -ne 0 ]; then + exec fakeroot "$0" +fi + +source PKGBUILD + +set -x + +pkgdir="${PWD}/${pkgname}_${pkgver}-${pkgrel}_all" + +umask 0022 +rm -rf "$pkgdir" +mkdir "${pkgdir}" "${pkgdir}/DEBIAN" + +"package" + +cat > "${pkgdir}/DEBIAN/control" < +Architecture: all +EOT + +dpkg-deb -b "${pkgdir}" + +rm -rf "${pkgdir}" diff --git a/systemd-monitor b/systemd-monitor new file mode 100755 index 0000000..21e249e --- /dev/null +++ b/systemd-monitor @@ -0,0 +1,15 @@ +#!/bin/bash + +function get_state { + systemctl show --property=SystemState +} + +sleep 60 + +while [ "$(get_state)" = "SystemState=running" ]; do + sleep 60 +done + +systemctl --failed | mail -s "$(get_state) on $(hostname)" root + +exit 1 diff --git a/systemd-monitor.service b/systemd-monitor.service new file mode 100644 index 0000000..412219b --- /dev/null +++ b/systemd-monitor.service @@ -0,0 +1,8 @@ +[Unit] +Description=Monitor systemd state and email root if there is a problem + +[Service] +ExecStart=/usr/bin/systemd-monitor + +[Install] +WantedBy=multi-user.target -- 2.39.2