Development

This commit is contained in:
Matthew Grotke 2026-05-25 17:03:44 -04:00
parent 4150c6ef6e
commit 63cf7dc2c4
2 changed files with 88 additions and 34 deletions

View file

@ -23,14 +23,23 @@ SCRIPT_DIR = Path(__file__).parent.resolve()
COMPOSE_FILE = SCRIPT_DIR.parent / "docker" / "routlin-dash" / "docker-compose.yml"
CADDYFILE = Path("/etc/caddy/Caddyfile")
FLASK_PORT = 25327
PRODUCT_NAME = os.environ.get('PRODUCT_NAME', 'routlin')
SYSTEMD_DIR = Path("/etc/systemd/system")
# Per-VLAN dnsmasq dotfiles (parallel to core.py constants)
DASHB_QUEUE_FILE = SCRIPT_DIR / ".dashboard-queue"
DASHB_DONE_FILE = SCRIPT_DIR / ".dashboard-done"
DASHB_LAST_RUN_FILE = SCRIPT_DIR / ".dashboard-last-run"
DASHB_LOCK_FILE = SCRIPT_DIR / ".dashboard-lock"
DASHB_PENDING_FILE = SCRIPT_DIR / ".dashboard-pending"
HEALTH_FILE = SCRIPT_DIR / ".health"
# Dashboard dotfiles
DASHB_QUEUE_FILE = SCRIPT_DIR / ".dashboard-queue"
DASHB_DONE_FILE = SCRIPT_DIR / ".dashboard-done"
DASHB_LAST_RUN_FILE = SCRIPT_DIR / ".dashboard-last-run"
DASHB_LOCK_FILE = SCRIPT_DIR / ".dashboard-lock"
DASHB_PENDING_FILE = SCRIPT_DIR / ".dashboard-pending"
DASHB_SCRIPT_FILE = SCRIPT_DIR / "do_dashboard_queue.sh"
HEALTH_FILE = SCRIPT_DIR / ".health"
# Dashboard systemd timer
DASHB_TIMER_NAME = f"{PRODUCT_NAME}-dashboard-queue"
DASHB_TIMER_FILE = SYSTEMD_DIR / f"{DASHB_TIMER_NAME}.timer"
DASHB_TIMER_SVC_FILE = SYSTEMD_DIR / f"{DASHB_TIMER_NAME}.service"
DASHB_TIMER_INTERVAL_SEC = 60
# ===================================================================
@ -339,6 +348,62 @@ def create_dotfiles():
os.chown(f, stat.st_uid, stat.st_gid)
# ===================================================================
# Dashboard systemd timer
# ===================================================================
def install_dashboard_timer():
description = "Routlin dashboard pending-update processor"
timer_content = "\n".join([
"# Generated by install.py -- do not edit manually.",
"",
"[Unit]",
f"Description={description}",
"",
"[Timer]",
f"OnActiveSec={DASHB_TIMER_INTERVAL_SEC}s",
f"OnUnitActiveSec={DASHB_TIMER_INTERVAL_SEC}s",
"AccuracySec=10s",
"",
"[Install]",
"WantedBy=timers.target",
"",
])
service_content = "\n".join([
"# Generated by install.py -- do not edit manually.",
"",
"[Unit]",
f"Description={description}",
"",
"[Service]",
"Type=oneshot",
f"ExecStart=/bin/bash {DASHB_SCRIPT_FILE}",
"",
])
for path, content in ((DASHB_TIMER_FILE, timer_content), (DASHB_TIMER_SVC_FILE, service_content)):
path.write_text(content)
print(f" Written: {path}")
subprocess.run(["systemctl", "daemon-reload"], capture_output=True, text=True)
active = subprocess.run(
["systemctl", "is-active", f"{DASHB_TIMER_NAME}.timer"],
capture_output=True, text=True,
).stdout.strip() == "active"
subprocess.run(["systemctl", "enable", f"{DASHB_TIMER_NAME}.timer"], capture_output=True, text=True)
subprocess.run(["systemctl", "restart" if active else "start", f"{DASHB_TIMER_NAME}.timer"],
capture_output=True, text=True)
print(f" Timer {DASHB_TIMER_NAME}.timer enabled (runs every {DASHB_TIMER_INTERVAL_SEC}s).")
def remove_dashboard_timer():
subprocess.run(["systemctl", "disable", "--now", f"{DASHB_TIMER_NAME}.timer"],
capture_output=True, text=True)
for f in (DASHB_TIMER_FILE, DASHB_TIMER_SVC_FILE):
if f.exists():
f.unlink()
print(f" Removed: {f}")
subprocess.run(["systemctl", "daemon-reload"], capture_output=True, text=True)
# ===================================================================
# Caddy
# ===================================================================
@ -518,6 +583,7 @@ def main():
if not want_dashboard:
print()
print(" Skipping dashboard setup.")
remove_dashboard_timer()
print()
print("Done.")
print(next_step)
@ -543,6 +609,10 @@ def main():
setup_docker_compose(reuse_config=reuse_config)
create_dotfiles()
# -- Dashboard timer -------------------------------------------
header("Dashboard Timer")
install_dashboard_timer()
# -- External access -------------------------------------------
header("External Access (optional)")
ext_domain = _external_access_domain()