Update setup_server.py
This commit is contained in:
parent
7443d431e5
commit
42ec00bb40
|
|
@ -708,24 +708,29 @@ 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
|
||||
# Scrivi lo script in /tmp e lanciato via systemd-run come transient unit
|
||||
# indipendente (NO --scope: lo scope eredita cgroup del padre, viene killato
|
||||
# quando setup_server muore prima che lo script completi i 5s di sleep + rm).
|
||||
script_path = "/tmp/argos-setup-cleanup.sh"
|
||||
try:
|
||||
with open(script_path, "w") as f:
|
||||
f.write(script)
|
||||
import os
|
||||
import os, time
|
||||
os.chmod(script_path, 0o755)
|
||||
|
||||
# systemd-run lancia in uno scope separato: sopravvive al termine di questo processo
|
||||
# systemd-run senza --scope: crea transient .service unit indipendente
|
||||
# che sopravvive al termine del processo padre. Unit name include
|
||||
# timestamp per evitare conflitti se setup viene rilanciato.
|
||||
unit_name = f"argos-setup-cleanup-{int(time.time())}.service"
|
||||
subprocess.Popen(
|
||||
["systemd-run", "--no-block", "--unit", "argos-setup-cleanup",
|
||||
"--scope", "/bin/bash", script_path],
|
||||
["systemd-run", "--no-block", "--unit", unit_name,
|
||||
"/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)")
|
||||
log(f"Cleanup schedulato via systemd-run come {unit_name} (delay 5s)")
|
||||
except Exception as e:
|
||||
log(f"Errore schedulazione cleanup: {e}")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue