mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 13:49:57 -05:00
Controller logs: an unparseable since is a 400, not empty logs (#953)
journalctl exits 1 with nothing on stdout when it cannot parse --since (a bare "1h" is one such value); the controller returned that empty stdout as the logs, with a 200. A failed journalctl is now an error: 400 when it could not parse since, 500 otherwise. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d25ebb9e63
commit
f3f762ef1b
4 changed files with 51 additions and 3 deletions
|
|
@ -528,10 +528,11 @@ def get_service_logs(name: str, lines: int = 100, since: Optional[str] = None) -
|
|||
Args:
|
||||
name: Service name from config
|
||||
lines: Number of lines to return
|
||||
since: Time specification (e.g., "1h", "30m", "2024-01-01")
|
||||
since: journalctl time specification (e.g., "-1h", "1 hour ago", "2024-01-01 09:00"). A bare "1h" is
|
||||
not one.
|
||||
|
||||
Returns:
|
||||
dict with logs and metadata
|
||||
dict with logs and metadata, or an "error" (with "invalid_since" when journalctl could not parse `since`)
|
||||
"""
|
||||
systemd_name = _get_systemd_name(name)
|
||||
if not systemd_name:
|
||||
|
|
@ -543,6 +544,10 @@ def get_service_logs(name: str, lines: int = 100, since: Optional[str] = None) -
|
|||
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
|
||||
if result.returncode != 0:
|
||||
# journalctl prints nothing to stdout when it fails; that must not read as "no logs".
|
||||
error = (result.stderr or "").strip() or f"journalctl exited with {result.returncode}"
|
||||
return {"error": error, "invalid_since": bool(since) and "Failed to parse timestamp" in error}
|
||||
return {
|
||||
"service": name,
|
||||
"lines": lines,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue