@@ -0,0 +1,16 @@
+[Unit]
+Description=Sleep Inhibitor Daemon
+After=multi-user.target suspend.target hibernate.target
+StartLimitIntervalSec=0
+
+[Service]
+Type=simple
+ExecStart=/usr/local/bin/sleep_inhibitor_daemon.sh
+Restart=always
+RestartSec=5
+StandardOutput=journal
+StandardError=journal
+[Install]
+WantedBy=multi-user.target suspend.target hibernate.target
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+#set -euo pipefail
+set -x
+while true
+do
+ if [ "$(mysql -sN mythconverg -e "SELECT DISTINCT 1 FROM record WHERE UTC_TIMESTAMP() BETWEEN ADDTIME(CAST(startdate AS DATETIME), starttime) AND DATE_ADD(ADDTIME(CAST(enddate AS DATETIME), endtime), INTERVAL 10 MINUTE)")" != "1" ]
+ then
+ sleep 10
+ continue
+ fi
+ {
+ systemd-inhibit --what=handle-lid-switch:sleep:shutdown:idle \
+ --who="SleepInhibitorDaemon" \
+ --why="Hibernate inhibited due to active TV recordings" \
+ sleep 90
+ } &
+ sleep 80
+done
+wait