refactor(wizard): service gira da -pkg + auto-cleanup fine install
Architettura precedente: - first-setup.sh copiava setup_server.py/setup.html/gen_config.py da /opt/argos-setup-pkg/ verso /opt/argos/setup/ - Service girava da /opt/argos/setup/ - Doppia cartella: git pull su -pkg non aggiornava il service Architettura nuova: - Service gira direttamente da /opt/argos-setup-pkg/ (nessuna copia) - A fine install _schedule_cleanup() lancia systemd-run --scope che: 1. attende 5s (permette risposta HTTP al browser) 2. stop+disable+rm argos-setup.service 3. chiude porta 8888 nel firewall 4. rm -rf /opt/argos-setup-pkg/ - Cartella /opt/argos/setup/ non viene piu' creata (rimossa da mkdir glob)
This commit is contained in:
parent
37876443df
commit
1537b23aa4
|
|
@ -80,10 +80,11 @@ success "Sudoers per restart servizi configurato"
|
||||||
# ══════════════════════════════════════════════════════════════════════════════
|
# ══════════════════════════════════════════════════════════════════════════════
|
||||||
section "4. Struttura cartelle"
|
section "4. Struttura cartelle"
|
||||||
# ══════════════════════════════════════════════════════════════════════════════
|
# ══════════════════════════════════════════════════════════════════════════════
|
||||||
mkdir -p /opt/argos/{app,config,data,feeds,logs,certs,backups,setup}
|
mkdir -p /opt/argos/{app,config,data,feeds,logs,certs,backups}
|
||||||
mkdir -p /opt/argos/config/assets
|
mkdir -p /opt/argos/config/assets
|
||||||
mkdir -p /opt/argos/data/{reports,models}
|
mkdir -p /opt/argos/data/{reports,models}
|
||||||
chown -R argos:argos /opt/argos
|
chown -R argos:argos /opt/argos
|
||||||
|
chown -R argos:argos /opt/argos-setup-pkg
|
||||||
chmod -R 750 /opt/argos
|
chmod -R 750 /opt/argos
|
||||||
# /opt/argos/feeds: pubblicamente leggibili (FortiGate ETF via nginx/www-data)
|
# /opt/argos/feeds: pubblicamente leggibili (FortiGate ETF via nginx/www-data)
|
||||||
chmod 755 /opt/argos/feeds
|
chmod 755 /opt/argos/feeds
|
||||||
|
|
@ -147,8 +148,8 @@ After=network.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=root
|
User=root
|
||||||
WorkingDirectory=/opt/argos/setup
|
WorkingDirectory=/opt/argos-setup-pkg
|
||||||
ExecStart=/usr/bin/python3 /opt/argos/setup/setup_server.py
|
ExecStart=/usr/bin/python3 /opt/argos-setup-pkg/setup_server.py
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=3
|
RestartSec=3
|
||||||
StandardOutput=journal
|
StandardOutput=journal
|
||||||
|
|
|
||||||
|
|
@ -448,6 +448,7 @@ def install(data):
|
||||||
log("Porta 8888 chiusa — web installer disabilitato")
|
log("Porta 8888 chiusa — web installer disabilitato")
|
||||||
|
|
||||||
log("=== INSTALLAZIONE COMPLETATA ===")
|
log("=== INSTALLAZIONE COMPLETATA ===")
|
||||||
|
_schedule_cleanup()
|
||||||
install_done = True
|
install_done = True
|
||||||
|
|
||||||
# Spegni il processo dopo 8s (tempo per inviare la risposta al browser)
|
# Spegni il processo dopo 8s (tempo per inviare la risposta al browser)
|
||||||
|
|
@ -668,6 +669,58 @@ class SetupHandler(BaseHTTPRequestHandler):
|
||||||
self.wfile.write(body)
|
self.wfile.write(body)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def _schedule_cleanup():
|
||||||
|
"""Schedula disabilitazione service argos-setup + rimozione /opt/argos-setup-pkg/.
|
||||||
|
|
||||||
|
Usa systemd-run --scope per lanciare in background con delay, cosi'
|
||||||
|
questa funzione puo' ritornare prima che il cleanup inizi (altrimenti
|
||||||
|
il processo cancellerebbe se stesso sotto i piedi).
|
||||||
|
"""
|
||||||
|
import subprocess, shlex
|
||||||
|
script = r"""#!/bin/bash
|
||||||
|
# Attendi 5 secondi per permettere al service padre di rispondere all'ultima
|
||||||
|
# richiesta HTTP di stato e chiudere pulito.
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
# Disabilita e ferma il service argos-setup
|
||||||
|
systemctl stop argos-setup.service 2>/dev/null || true
|
||||||
|
systemctl disable argos-setup.service 2>/dev/null || true
|
||||||
|
rm -f /etc/systemd/system/argos-setup.service
|
||||||
|
systemctl daemon-reload
|
||||||
|
|
||||||
|
# Chiudi porta 8888 nel firewall
|
||||||
|
ufw delete allow 8888/tcp 2>/dev/null || true
|
||||||
|
|
||||||
|
# Rimuovi la cartella del pacchetto (auto-delete del codice corrente)
|
||||||
|
rm -rf /opt/argos-setup-pkg
|
||||||
|
|
||||||
|
# Log
|
||||||
|
echo "argos-setup cleanup completato $(date -Iseconds)" >> /var/log/argos-setup-cleanup.log
|
||||||
|
"""
|
||||||
|
# Scrivi lo script in /tmp e lanciato via systemd-run detached
|
||||||
|
script_path = "/tmp/argos-setup-cleanup.sh"
|
||||||
|
try:
|
||||||
|
with open(script_path, "w") as f:
|
||||||
|
f.write(script)
|
||||||
|
import os
|
||||||
|
os.chmod(script_path, 0o755)
|
||||||
|
|
||||||
|
# systemd-run lancia in uno scope separato: sopravvive al termine di questo processo
|
||||||
|
subprocess.Popen(
|
||||||
|
["systemd-run", "--no-block", "--unit", "argos-setup-cleanup",
|
||||||
|
"--scope", "/bin/bash", script_path],
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
start_new_session=True,
|
||||||
|
)
|
||||||
|
log("Cleanup schedulato via systemd-run (delay 5s)")
|
||||||
|
except Exception as e:
|
||||||
|
log(f"Errore schedulazione cleanup: {e}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(f"\n{'='*55}")
|
print(f"\n{'='*55}")
|
||||||
print(f" ARGOS SOC — Web Installer")
|
print(f" ARGOS SOC — Web Installer")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue