diff --git a/backend/services/platform_info.py b/backend/services/platform_info.py new file mode 100644 index 0000000..a9c1501 --- /dev/null +++ b/backend/services/platform_info.py @@ -0,0 +1,25 @@ +""" +Platform/Virtualization Detection +Einmalige Prüfung via systemd-detect-virt beim Start. +""" + +import subprocess +import logging + +logger = logging.getLogger(__name__) + + +def _detect_virt() -> str: + try: + r = subprocess.run(["/usr/bin/systemd-detect-virt"], capture_output=True, text=True, timeout=3) + return r.stdout.strip() + except Exception: + return "none" + + +VIRT_TYPE = _detect_virt() +IS_CONTAINER = VIRT_TYPE not in ("none", "") +IS_LXC = VIRT_TYPE == "lxc" + +if IS_CONTAINER: + logger.info(f"Running inside container (virt={VIRT_TYPE}) — hardware-specific checks disabled") diff --git a/backend/services/system_info.py b/backend/services/system_info.py index 92129b2..472655a 100644 --- a/backend/services/system_info.py +++ b/backend/services/system_info.py @@ -10,6 +10,8 @@ import platform from typing import Dict, Any, Optional from datetime import datetime +from services.platform_info import IS_CONTAINER + logger = logging.getLogger(__name__) @@ -297,16 +299,8 @@ def get_network_traffic() -> Dict[str, Any]: return {"error": str(e)} -def _is_container() -> bool: - try: - r = subprocess.run(["/usr/bin/systemd-detect-virt"], capture_output=True, text=True, timeout=3) - return r.returncode == 0 and r.stdout.strip() not in ("none", "") - except Exception: - return False - - def get_disk_io() -> Dict[str, Any]: - if _is_container(): + if IS_CONTAINER: return {"disks": []} try: with open("/proc/diskstats", "r") as f: diff --git a/backend/services/zfs_runner.py b/backend/services/zfs_runner.py index a227368..2f79c79 100644 --- a/backend/services/zfs_runner.py +++ b/backend/services/zfs_runner.py @@ -11,6 +11,8 @@ import re from typing import Dict, List, Any, Optional, Tuple from datetime import datetime, timedelta +from services.platform_info import IS_CONTAINER + logger = logging.getLogger(__name__) _TIMEOUT = 5 @@ -189,6 +191,8 @@ def scrub_pool(pool_name: str) -> Dict[str, str]: def get_smart_info(disk: str) -> Dict[str, Any]: + if IS_CONTAINER: + return {"available": False, "reason": "container"} stdout, _, rc = _run(["smartctl", "-A", "-i", "--json", f"/dev/{disk}"]) if not stdout: return {}