Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supervisor container startup health function #2214

Merged
merged 6 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()