mirror of
https://github.com/myronblair/kino-app
synced 2026-07-28 05:23:45 -05:00
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""Docker service status/restart for the internal StreamHoard stack."""
|
|
import docker
|
|
|
|
SERVICES = [
|
|
{"key": "gluetun", "label": "VPN (gluetun)", "container": "streamhoard-gluetun"},
|
|
{"key": "sonarr", "label": "Sonarr", "container": "streamhoard-sonarr"},
|
|
{"key": "radarr", "label": "Radarr", "container": "streamhoard-radarr"},
|
|
{"key": "prowlarr", "label": "Prowlarr", "container": "streamhoard-prowlarr"},
|
|
{"key": "qbittorrent", "label": "qBittorrent", "container": "streamhoard-qbittorrent"},
|
|
{"key": "mongo", "label": "Database", "container": "streamhoard-mongo"},
|
|
{"key": "portainer", "label": "Portainer", "container": "streamhoard-portainer"},
|
|
]
|
|
|
|
_client = None
|
|
|
|
|
|
def _get_client():
|
|
global _client
|
|
if _client is None:
|
|
_client = docker.DockerClient(base_url="unix:///var/run/docker.sock")
|
|
return _client
|
|
|
|
|
|
def list_service_status():
|
|
client = _get_client()
|
|
out = []
|
|
for svc in SERVICES:
|
|
try:
|
|
c = client.containers.get(svc["container"])
|
|
running = c.status == "running"
|
|
except docker.errors.NotFound:
|
|
running = False
|
|
except Exception:
|
|
running = False
|
|
out.append({"key": svc["key"], "label": svc["label"], "running": running})
|
|
return out
|
|
|
|
|
|
def restart_service(key: str) -> bool:
|
|
svc = next((s for s in SERVICES if s["key"] == key), None)
|
|
if not svc:
|
|
return False
|
|
client = _get_client()
|
|
c = client.containers.get(svc["container"])
|
|
c.restart(timeout=15)
|
|
return True
|