Expose Buildroot image version

This commit is contained in:
Yellowcooln
2026-04-29 09:27:56 -04:00
parent 465372587b
commit 8856268ef2
2 changed files with 31 additions and 2 deletions
+24 -2
View File
@@ -6,14 +6,15 @@ Provides functions for service control operations like restart.
import logging
import os
import subprocess
from typing import Tuple
from typing import Dict, Optional, Tuple
logger = logging.getLogger("ServiceUtils")
INIT_SCRIPT = "/etc/init.d/S80pymc-repeater"
BUILDROOT_METADATA_PATH = "/etc/pymc-image-build-id"
def is_buildroot() -> bool:
if os.path.exists("/etc/pymc-image-build-id"):
if os.path.exists(BUILDROOT_METADATA_PATH):
return True
if os.path.exists("/etc/os-release"):
try:
@@ -24,6 +25,27 @@ def is_buildroot() -> bool:
return False
def get_buildroot_image_info() -> Dict[str, str]:
info: Dict[str, str] = {}
try:
with open(BUILDROOT_METADATA_PATH, "r", encoding="utf-8") as handle:
for line in handle:
line = line.strip()
if not line or "=" not in line:
continue
key, value = line.split("=", 1)
info[key.strip()] = value.strip()
except OSError:
return {}
return info
def get_buildroot_image_version() -> Optional[str]:
return get_buildroot_image_info().get("image_version")
def restart_service() -> Tuple[bool, str]:
"""
Restart the pymc-repeater service.
+7
View File
@@ -16,6 +16,7 @@ from repeater.companion.identity_resolve import (
heal_companion_empty_names,
)
from repeater.config import update_unscoped_flood_policy
from repeater.service_utils import get_buildroot_image_info
from .auth.middleware import require_auth
from .auth_endpoints import AuthAPIEndpoints
@@ -625,6 +626,12 @@ class APIEndpoints:
stats["core_version"] = pymc_core.__version__
except ImportError:
stats["core_version"] = "unknown"
image_info = get_buildroot_image_info()
if image_info:
if image_info.get("image_name"):
stats["image_name"] = image_info["image_name"]
if image_info.get("image_version"):
stats["image_version"] = image_info["image_version"]
return stats
except Exception as e:
logger.error(f"Error serving stats: {e}")