From 8378dc5c696b051b4804720e92734b2417bbc3e7 Mon Sep 17 00:00:00 2001 From: Adrian Vladu Date: Thu, 30 Jul 2026 10:57:08 +0300 Subject: [PATCH] add sigterm and exit handlers Change-Id: Ifbfeed6b23a9cbce46cd4cb1724e5c769646653b Signed-off-by: Adrian Vladu --- cloudbaseinit/shell.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cloudbaseinit/shell.py b/cloudbaseinit/shell.py index 2a25c3c53..3d8fc3599 100644 --- a/cloudbaseinit/shell.py +++ b/cloudbaseinit/shell.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +import atexit +import signal import sys from oslo_log import log as oslo_logging @@ -29,6 +31,20 @@ def main(): CONF(sys.argv[1:]) logging.setup('cloudbaseinit') + def atexit_handler(): + LOG.debug("Process is exiting") + try: + atexit.register(atexit_handler) + except Exception as exc: + LOG.exception(exc) + + def on_sigterm_handler(sig, frame): + LOG.debug("Process has received sigterm") + try: + signal.signal(signal.SIGTERM, on_sigterm_handler) + except Exception as exc: + LOG.exception(exc) + try: init.InitManager().configure_host() except Exception as exc: