diff --git a/ober/README.md b/ober/README.md index 7b64311..dce06f3 100644 --- a/ober/README.md +++ b/ober/README.md @@ -7,7 +7,7 @@ en [klant-ip] door het ip-adres van het rekentuig dat de klant draait. - Als je het programmaatje niet als root wilt uitvoeren, verander dan ook de gebruiker in dit script. -3. Plaats aiuo-shutdown.service, aiuo-shutdown-suspend.service en aiuo-wakeup.service in `/etc/systemd/system`. +3. Plaats aiuo-shutdown.service en aiuo-shutdown-sleep.service in `/etc/systemd/system`. 4. Start deze services met systemd. Als je zeker weet dat het werkt, schakel het dan in. - Ik heb mijn rekentuig een keer onopstartbaar gemaakt, omdat het zichzelf meteen afsloot. Houd hier rekening mee! diff --git a/ober/aiuo-shutdown-sleep.service b/ober/aiuo-shutdown-sleep.service new file mode 100644 index 0000000..7d2bda6 --- /dev/null +++ b/ober/aiuo-shutdown-sleep.service @@ -0,0 +1,13 @@ +[Unit] +Description=AIUO sleep hook +Before=sleep.target +StopWhenUnneeded=yes + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=-aiuo-shutdown --notify sleep +ExecStop=-aiuo-shutdown --notify wakeup + +[Install] +WantedBy=sleep.target diff --git a/ober/aiuo-shutdown-suspend.service b/ober/aiuo-shutdown-suspend.service deleted file mode 100644 index a233a20..0000000 --- a/ober/aiuo-shutdown-suspend.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Notify aiuo-shutdown when system goes sleeping -StopWhenUnneeded=yes - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStop=aiuo-shutdown --notify sleep - -[Install] -WantedBy=sleep.target diff --git a/ober/aiuo-shutdown-wakeup.service b/ober/aiuo-shutdown-wakeup.service deleted file mode 100644 index eb054c1..0000000 --- a/ober/aiuo-shutdown-wakeup.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Notify aiuo-shutdown when system wakes up -After=sleep.target -StopWhenUnneeded=yes - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStop=aiuo-shutdown --notify wakeup - -[Install] -WantedBy=suspend.target diff --git a/ober/aiuo-shutdown.service b/ober/aiuo-shutdown.service index 2fdd0ec..844138f 100644 --- a/ober/aiuo-shutdown.service +++ b/ober/aiuo-shutdown.service @@ -6,6 +6,8 @@ After=network-online.target [Service] Type=idle ExecStart=aiuo-shutdown [wachttijd] [klant-ip] +Restart=on-failure +RestartSec=3 User=root [Install] diff --git a/ober/ober/autoshutdown.py b/ober/ober/autoshutdown.py index aa9ebad..3813548 100755 --- a/ober/ober/autoshutdown.py +++ b/ober/ober/autoshutdown.py @@ -58,11 +58,13 @@ def sigterm_handler(signum, frame): def sigusr1_handler(signum, frame): LOGGER.debug("Going to sleep") - client.notify("NotifySleep") + if client: + client.notify("NotifySleep") def sigusr2_handler(signum, frame): LOGGER.debug("Waking up") - client.notify("NotifyWakeup") + if client: + client.notify("NotifyWakeup") def main() -> None: @@ -87,7 +89,6 @@ def main() -> None: LOGGER.debug(client.call("GetBootReason")) # Alleen de klant op de hoogte stellen nadat we hebben laten weten dat we er zijn. LOGGER.debug("signalen registreren") - #loop.add_signal_handler(signal.SIGINT, lambda: asyncio.ensure_future(sigint_handler())) signal.signal(signal.SIGTERM, sigterm_handler) signal.signal(signal.SIGUSR1, sigusr1_handler) signal.signal(signal.SIGUSR2, sigusr2_handler)