fix: remove legacy service dirs from setup_cell, update sanity_check for optional services
Unit Tests / test (push) Successful in 11m24s

setup_cell.py no longer creates mail/radicale/webdav config and data dirs —
those are managed by ServiceComposer when services are installed. Added
data/services/ for ServiceComposer. sanity_check.py now uses stdlib urllib
and discovers installed services via /api/services/active before checking
their status routes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-29 17:22:42 -04:00
parent 10ac15d9fe
commit 3d594025d2
2 changed files with 54 additions and 59 deletions
+53 -48
View File
@@ -1,60 +1,65 @@
import requests import json
from bs4 import BeautifulSoup import sys
import urllib.request
import urllib.error
# Updated endpoints to use HTTPS BASE = "http://127.0.0.1:3000"
SERVICES = [
{"name": "Dashboard UI", "url": "https://localhost/"}, CORE_CHECKS = [
{"name": "Mail UI", "url": "https://localhost/mail"}, {"name": "API health", "path": "/health"},
{"name": "Calendar UI", "url": "https://localhost/calendar"}, {"name": "API status", "path": "/api/status"},
{"name": "Files UI", "url": "https://localhost/files"}, {"name": "Active services", "path": "/api/services/active"},
{"name": "DNS Management UI", "url": "https://localhost/dns"},
{"name": "API Health", "url": "https://localhost/api/health", "is_api": True},
{"name": "API Service Status", "url": "https://localhost/api/services/status", "is_api": True},
] ]
def check_ui(url, name): OPTIONAL_SERVICE_CHECKS = {
try: "email": {"name": "Email status", "path": "/api/email/status"},
resp = requests.get(url, timeout=5, verify=False) "calendar": {"name": "Calendar status", "path": "/api/calendar/status"},
if resp.status_code == 200: "files": {"name": "Files status", "path": "/api/files/status"},
# Try to parse HTML and look for a title or main element }
soup = BeautifulSoup(resp.text, "html.parser")
title = soup.title.string if soup.title else "No title"
print(f"[OK] {name} ({url}) - {title}")
return True
else:
print(f"[FAIL] {name} ({url}) - HTTP {resp.status_code}")
return False
except Exception as e:
print(f"[ERROR] {name} ({url}) - {e}")
return False
def check_api_status(url, name):
def get(path):
try: try:
resp = requests.get(url, timeout=5, verify=False) resp = urllib.request.urlopen(BASE + path, timeout=5)
if resp.status_code == 200: body = resp.read().decode()
print(f"[OK] {name}: {url}") return resp.status, body
if 'services/status' in url: except urllib.error.HTTPError as e:
data = resp.json() return e.code, e.read().decode()
for service, status in data.items():
s = status.get("status", "Unknown")
print(f" {service}: {s}")
else:
print(f" Response: {resp.text.strip()}")
return True
else:
print(f"[FAIL] {name}: HTTP {resp.status_code}")
return False
except Exception as e: except Exception as e:
print(f"[ERROR] {name}: {e}") return None, str(e)
return False
def main(): def main():
print("=== UI & API Sanity Checks (Caddy-proxied, HTTPS) ===") print("=== PIC Sanity Check ===")
for svc in SERVICES:
if svc.get("is_api"): for chk in CORE_CHECKS:
check_api_status(svc["url"], svc["name"]) code, body = get(chk["path"])
if code == 200:
print(f"[OK] {chk['name']}")
else: else:
check_ui(svc["url"], svc["name"]) print(f"[FAIL] {chk['name']} — HTTP {code}: {body[:120]}")
# Discover installed services and check only those
code, body = get("/api/services/active")
installed_ids = set()
if code == 200:
try:
installed_ids = {svc["id"] for svc in json.loads(body)}
except Exception:
pass
print()
print("Optional services:")
for svc_id, chk in OPTIONAL_SERVICE_CHECKS.items():
if svc_id not in installed_ids:
print(f"[SKIP] {chk['name']} — not installed")
continue
code, body = get(chk["path"])
if code == 200:
print(f"[OK] {chk['name']}")
else:
print(f"[FAIL] {chk['name']} — HTTP {code}: {body[:120]}")
if __name__ == "__main__": if __name__ == "__main__":
main() main()
+1 -11
View File
@@ -19,26 +19,18 @@ REQUIRED_DIRS = [
'config/dns', 'config/dns',
'config/dhcp', 'config/dhcp',
'config/ntp', 'config/ntp',
'config/mail/config',
'config/mail/ssl',
'config/radicale',
'config/webdav',
'config/wireguard', 'config/wireguard',
'config/api', 'config/api',
'data/caddy', 'data/caddy',
'data/dns', 'data/dns',
'data/dhcp', 'data/dhcp',
'data/maildata',
'data/mailstate',
'data/maillogs',
'data/radicale',
'data/files',
'data/api', 'data/api',
'data/vault/certs', 'data/vault/certs',
'data/vault/keys', 'data/vault/keys',
'data/vault/trust', 'data/vault/trust',
'data/vault/ca', 'data/vault/ca',
'data/logs', 'data/logs',
'data/services',
'data/wireguard/keys/peers', 'data/wireguard/keys/peers',
'data/wireguard/wg_confs', 'data/wireguard/wg_confs',
] ]
@@ -47,8 +39,6 @@ REQUIRED_FILES = [
'config/dns/Corefile', 'config/dns/Corefile',
'config/dhcp/dnsmasq.conf', 'config/dhcp/dnsmasq.conf',
'config/ntp/chrony.conf', 'config/ntp/chrony.conf',
'config/mail/mailserver.env',
'config/webdav/users.passwd',
] ]
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))