Feat: update agent version to 1.2.0 and add systemd services listing in VpsCard component
All checks were successful
Build and Push Docker Images / docker (push) Successful in 25s
All checks were successful
Build and Push Docker Images / docker (push) Successful in 25s
This commit is contained in:
@@ -19,7 +19,7 @@ from fastapi.security import APIKeyHeader
|
||||
|
||||
# ─── Config ───────────────────────────────────────────────────────────────────
|
||||
|
||||
AGENT_VERSION = "1.1.0"
|
||||
AGENT_VERSION = "1.2.0"
|
||||
|
||||
REPO_BASE = os.getenv("AGENT_REPO_BASE", "https://git.jeanbonapp.com/jeanbon/ScriptVPS/raw/branch/main")
|
||||
INSTALL_DIR = os.getenv("AGENT_INSTALL_DIR", "/opt/vps-monitor-agent")
|
||||
@@ -219,6 +219,46 @@ def compose_update(project: str, _: None = Depends(require_api_key)):
|
||||
return {"output": output, "project": project, "working_dir": working_dir}
|
||||
|
||||
|
||||
@app.get("/services")
|
||||
def list_services(_: None = Depends(require_api_key)):
|
||||
"""Retourne la liste des services systemd (hors Docker) avec leur état."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["systemctl", "list-units", "--type=service", "--no-legend", "--no-pager", "--all"],
|
||||
capture_output=True, text=True, timeout=10,
|
||||
)
|
||||
except FileNotFoundError:
|
||||
raise HTTPException(status_code=501, detail="systemctl introuvable — système non-systemd")
|
||||
except subprocess.TimeoutExpired:
|
||||
raise HTTPException(status_code=504, detail="systemctl a expiré")
|
||||
|
||||
_DOCKER_SERVICES = {"docker.service", "containerd.service", "docker.socket"}
|
||||
|
||||
services = []
|
||||
for line in result.stdout.strip().splitlines():
|
||||
# Supprime les puces (● ○) et les espaces de début
|
||||
line = line.lstrip("●○").strip()
|
||||
if not line:
|
||||
continue
|
||||
parts = line.split(None, 4)
|
||||
if len(parts) < 4:
|
||||
continue
|
||||
name = parts[0]
|
||||
if not name.endswith(".service"):
|
||||
continue
|
||||
if name.lower() in _DOCKER_SERVICES or name.lower().startswith("docker"):
|
||||
continue
|
||||
services.append({
|
||||
"name": name,
|
||||
"load": parts[1],
|
||||
"active": parts[2],
|
||||
"sub": parts[3],
|
||||
"description": parts[4].strip() if len(parts) > 4 else "",
|
||||
})
|
||||
|
||||
return sorted(services, key=lambda s: s["name"])
|
||||
|
||||
|
||||
# ─── Entrée ───────────────────────────────────────────────────────────────────
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user