--- /dev/null
+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/"
+}
--- /dev/null
+#!/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}"
--- /dev/null
+#!/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
--- /dev/null
+[Unit]
+Description=Monitor systemd state and email root if there is a problem
+
+[Service]
+ExecStart=/usr/bin/systemd-monitor
+
+[Install]
+WantedBy=multi-user.target