From 28344ff5f35bb4e0fa18f7b432be8665fd8afe3a Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Tue, 3 Nov 2020 16:36:10 +0100 Subject: [PATCH] Supervisor container startup health function (#2214) * Supervisor container startup health function * better struct * add test * address comment * rename file * Update tests/test_main.py Co-authored-by: Stefan Agner Co-authored-by: Stefan Agner --- supervisor/__main__.py | 17 +++++++++++++++++ tests/test_main.py | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/test_main.py diff --git a/supervisor/__main__.py b/supervisor/__main__.py index c5e0e2613..5e093ccdc 100644 --- a/supervisor/__main__.py +++ b/supervisor/__main__.py @@ -2,12 +2,26 @@ import asyncio from concurrent.futures import ThreadPoolExecutor import logging +from pathlib import Path import sys from supervisor import bootstrap _LOGGER: logging.Logger = logging.getLogger(__name__) +CONTAINER_OS_STARTUP_CHECK = Path("/run/os/startup-marker") + + +def run_os_startup_check_cleanup() -> None: + """Cleanup OS startup check.""" + if not CONTAINER_OS_STARTUP_CHECK.exists(): + return + + try: + CONTAINER_OS_STARTUP_CHECK.unlink() + except OSError as err: + _LOGGER.warning("Not able to remove the startup health file: %s", err) + # pylint: disable=invalid-name if __name__ == "__main__": @@ -30,6 +44,9 @@ if __name__ == "__main__": bootstrap.supervisor_debugger(coresys) bootstrap.migrate_system_env(coresys) + # Signal health startup for container + run_os_startup_check_cleanup() + _LOGGER.info("Setting up Supervisor") loop.run_until_complete(coresys.core.setup()) diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 000000000..ef2e4f4c4 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,17 @@ +"""Testing handling with main.""" +from pathlib import Path + +import supervisor.__main__ as main + + +def test_write_state(tmp_path): + """Test startup-marker file cleanup.""" + test_file = Path(tmp_path, "test.file") + + test_file.touch() + assert test_file.exists() + + main.CONTAINER_OS_STARTUP_CHECK = test_file + main.run_os_startup_check_cleanup() + + assert not test_file.exists()