Add automatic Speaches container lifecycle management

This commit is contained in:
2026-11-23 21:17:16 +03:00
parent 5c5827d241
commit 115fb5acb9
2 changed files with 128 additions and 2 deletions
+36
View File
@@ -339,9 +339,45 @@ def system_power(action):
)
return 0
def speaches_control(action):
"""Manage only the dedicated Speaches container."""
if action not in {"start", "stop"}:
return 2
docker = "/usr/bin/docker"
container = "speaches"
state = run(
docker,
"inspect",
"--format",
"{{.State.Running}}",
container,
timeout=10,
).stdout.strip().lower()
if state not in {"true", "false"}:
raise RuntimeError(f"Unexpected Speaches container state: {state}")
if action == "start":
if state == "true":
return 0
run(docker, "start", container, timeout=60)
return 0
if state == "false":
return 0
run(docker, "stop", "--time", "10", container, timeout=30)
return 0
def main():
if len(sys.argv) != 3: return 2
action, value = sys.argv[1:]
if action == "speaches-control":
return speaches_control(value)
if action == 'hostname':
if len(value) > 63 or not re.fullmatch(r'[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?', value): return 2
run('/usr/bin/hostnamectl', 'set-hostname', value); return 0