update check active
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
from pathlib import Path
|
||||
from pathlib import Path, PurePosixPath
|
||||
|
||||
from app.core.command_runner import CommandError, CommandRunner
|
||||
|
||||
@@ -125,6 +125,38 @@ class AptInstaller(DebInstaller):
|
||||
env=APT_NONINTERACTIVE_ENV,
|
||||
)
|
||||
|
||||
def discover_service_units(self, package_name: str) -> list[str]:
|
||||
"""Return concrete systemd service units shipped by an installed package.
|
||||
|
||||
The package name is already constrained by the Agent APT allowlist. It is
|
||||
still passed as a single argv item and no shell expansion is performed.
|
||||
Template units are omitted because they cannot be meaningfully checked
|
||||
without an instance name.
|
||||
"""
|
||||
try:
|
||||
result = self.command_runner.run(
|
||||
["dpkg-query", "-L", package_name],
|
||||
timeout=30,
|
||||
log_output=False,
|
||||
)
|
||||
except CommandError:
|
||||
return []
|
||||
|
||||
service_names: set[str] = set()
|
||||
for raw_path in result.stdout.splitlines():
|
||||
path = raw_path.strip()
|
||||
if not path.endswith(".service"):
|
||||
continue
|
||||
if "/systemd/system/" not in path:
|
||||
continue
|
||||
|
||||
service_name = PurePosixPath(path).name
|
||||
if "@" in service_name:
|
||||
continue
|
||||
service_names.add(service_name)
|
||||
|
||||
return sorted(service_names)
|
||||
|
||||
def wait_for_postgresql(
|
||||
self,
|
||||
attempts: int = 6,
|
||||
@@ -141,3 +173,10 @@ class AptInstaller(DebInstaller):
|
||||
time.sleep(delay_seconds)
|
||||
|
||||
raise RuntimeError("PostgreSQL did not become ready after installation") from last_error
|
||||
|
||||
def is_postgresql_ready(self) -> bool:
|
||||
try:
|
||||
self.command_runner.run(["pg_isready", "--timeout=5"], timeout=10)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user