From ceb06abce6334ed0cde6c64e52f475a52b16eba2 Mon Sep 17 00:00:00 2001 From: Chris Josten Date: Sat, 2 Jan 2021 15:38:46 +0100 Subject: [PATCH] Improved shutting down --- ober/ober/autoshutdown.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ober/ober/autoshutdown.py b/ober/ober/autoshutdown.py index 3813548..c2f000f 100755 --- a/ober/ober/autoshutdown.py +++ b/ober/ober/autoshutdown.py @@ -5,6 +5,7 @@ import asyncio import logging import os import signal +import sys import subprocess import time @@ -54,7 +55,8 @@ def trusty_sleep(amount: float): def sigterm_handler(signum, frame): LOGGER.debug("Notifying of shutdown") - client.notify("NotifyShutdown") + prepareShutdown() + sys.exit(0) def sigusr1_handler(signum, frame): LOGGER.debug("Going to sleep") @@ -66,6 +68,8 @@ def sigusr2_handler(signum, frame): if client: client.notify("NotifyWakeup") +def prepareShutdown(): + client.notify("NotifyShutdown") def main() -> None: global TIMEOUT @@ -107,7 +111,7 @@ def main() -> None: last_checked_value = True else: last_checked_value = False - sigterm_handler() + prepareShutdown() os.system("shutdown +1 The system is going to shut down because no active sessions were found and no one is on the server")