]> code.delx.au - systemd-monitor/commitdiff
Initial commit
authorJames Bunton <jamesbunton@delx.net.au>
Tue, 19 Jun 2018 07:12:10 +0000 (17:12 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Tue, 19 Jun 2018 07:15:32 +0000 (17:15 +1000)
PKGBUILD [new file with mode: 0644]
makedeb [new file with mode: 0755]
systemd-monitor [new file with mode: 0755]
systemd-monitor.service [new file with mode: 0644]

diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644 (file)
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 (executable)
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" <<EOT
+Section: misc
+Priority: optional
+Standards-Version: 3.9.2
+Package: ${pkgname}
+Description: ${pkgdesc}
+Version: ${pkgver}-${pkgrel}
+Maintainer: James Bunton <jamesbunton@delx.net.au>
+Architecture: all
+EOT
+
+dpkg-deb -b "${pkgdir}"
+
+rm -rf "${pkgdir}"
diff --git a/systemd-monitor b/systemd-monitor
new file mode 100755 (executable)
index 0000000..21e249e
--- /dev/null
@@ -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 (file)
index 0000000..412219b
--- /dev/null
@@ -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