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 <stefan@agner.ch> Co-authored-by: Stefan Agner <stefan@agner.ch>
This commit is contained in:
parent
608ae14246
commit
28344ff5f3
|
@ -2,12 +2,26 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
import logging
|
import logging
|
||||||
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from supervisor import bootstrap
|
from supervisor import bootstrap
|
||||||
|
|
||||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
_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
|
# pylint: disable=invalid-name
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -30,6 +44,9 @@ if __name__ == "__main__":
|
||||||
bootstrap.supervisor_debugger(coresys)
|
bootstrap.supervisor_debugger(coresys)
|
||||||
bootstrap.migrate_system_env(coresys)
|
bootstrap.migrate_system_env(coresys)
|
||||||
|
|
||||||
|
# Signal health startup for container
|
||||||
|
run_os_startup_check_cleanup()
|
||||||
|
|
||||||
_LOGGER.info("Setting up Supervisor")
|
_LOGGER.info("Setting up Supervisor")
|
||||||
loop.run_until_complete(coresys.core.setup())
|
loop.run_until_complete(coresys.core.setup())
|
||||||
|
|
||||||
|
|
|
@ -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()
|
Loading…
Reference in New Issue