Update setup_server.py
This commit is contained in:
parent
f9a7a916b4
commit
cd625f9103
|
|
@ -524,8 +524,12 @@ extendedKeyUsage = serverAuth
|
||||||
log("── Creazione e avvio servizi ──")
|
log("── Creazione e avvio servizi ──")
|
||||||
_write_services()
|
_write_services()
|
||||||
run("systemctl daemon-reload")
|
run("systemctl daemon-reload")
|
||||||
for svc in ["argos-backend", "argos-sync", "argos-ops", "argos-analytics",
|
svc_list = ["argos-backend", "argos-sync", "argos-ops", "argos-analytics",
|
||||||
"argos-updater"]:
|
"argos-updater"]
|
||||||
|
# Watchguard: solo se la unit è stata generata (demone presente nel repo)
|
||||||
|
if Path("/etc/systemd/system/argos-watchguard.service").exists():
|
||||||
|
svc_list.append("argos-watchguard")
|
||||||
|
for svc in svc_list:
|
||||||
run(f"systemctl enable --now {svc}")
|
run(f"systemctl enable --now {svc}")
|
||||||
log(f"{svc} avviato")
|
log(f"{svc} avviato")
|
||||||
|
|
||||||
|
|
@ -748,6 +752,47 @@ WantedBy=multi-user.target
|
||||||
with open(f"/etc/systemd/system/argos-{svc}.service", "w") as f:
|
with open(f"/etc/systemd/system/argos-{svc}.service", "w") as f:
|
||||||
f.write(unit)
|
f.write(unit)
|
||||||
|
|
||||||
|
# ── argos-watchguard: demone di supervisione autonomo ────────────────────
|
||||||
|
# NON è Gunicorn (loop Python puro), quindi unit dedicata fuori dal loop.
|
||||||
|
# Non ha After=argos-analytics: deve girare anche se gli altri sono giù.
|
||||||
|
wg_src = f"{services_dir}/argos_watchguard.py"
|
||||||
|
if Path(wg_src).exists():
|
||||||
|
# python3-systemd opzionale (solo per WatchdogSec). Se assente, ok senza.
|
||||||
|
wg_watchdog = ""
|
||||||
|
try:
|
||||||
|
subprocess.run([f"{venv_bin}/python3", "-c", "import systemd.daemon"],
|
||||||
|
check=True, capture_output=True)
|
||||||
|
wg_watchdog = "WatchdogSec=300\n"
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
wg_unit = f"""[Unit]
|
||||||
|
Description=ARGOS Watchguard — supervisione autonoma servizi/cache/log
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User={APP_USER}
|
||||||
|
Group={APP_USER}
|
||||||
|
WorkingDirectory={backend_dir}
|
||||||
|
Environment=PYTHONPATH={backend_dir}:{services_dir}
|
||||||
|
Environment=ARGOS_DATA={DATA_DIR}
|
||||||
|
Environment=ARGOS_LOGS={LOGS_DIR}
|
||||||
|
Environment=WATCHGUARD_INTERVAL=120
|
||||||
|
Environment=WATCHGUARD_STALE_FACTOR=2.0
|
||||||
|
Environment=WATCHGUARD_LOG_WINDOW_MIN=60
|
||||||
|
ExecStart={venv_bin}/python {wg_src}
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
|
StandardOutput=journal
|
||||||
|
StandardError=journal
|
||||||
|
SyslogIdentifier=argos-watchguard
|
||||||
|
{wg_watchdog}
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
"""
|
||||||
|
with open("/etc/systemd/system/argos-watchguard.service", "w") as f:
|
||||||
|
f.write(wg_unit)
|
||||||
|
|
||||||
|
|
||||||
class SetupHandler(BaseHTTPRequestHandler):
|
class SetupHandler(BaseHTTPRequestHandler):
|
||||||
def log_message(self, *args): pass
|
def log_message(self, *args): pass
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue