Skip to content

Commit

Permalink
Supervisor container startup health function (#2214)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
pvizeli and agners committed Nov 3, 2020
1 parent 608ae14 commit 28344ff
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions supervisor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand All @@ -30,6 +44,9 @@
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())

Expand Down
17 changes: 17 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 28344ff

Please sign in to comment.