feat: implement server-wide management actions and enhance TUI dashboard

This commit is contained in:
2026-03-04 20:51:02 +00:00
parent 150f9d2990
commit ddec55871b
13 changed files with 621 additions and 52 deletions
+22 -8
View File
@@ -18,23 +18,37 @@ while IFS='|' read -r id _version _enabled _desc _cfg; do
continue
fi
local_pid="$(read_pid "$id")"
kill -TERM "$local_pid" 2>/dev/null || true
# Kill ALL instances, not just the one in the PID file
all_pids="$(find_agent_pids "$id")"
instance_count="$(echo "$all_pids" | grep -c . 2>/dev/null || echo 0)"
# Espera hasta 5s a que muera limpiamente
if [[ "$instance_count" -gt 1 ]]; then
warn "$id has $instance_count instances running — stopping all"
fi
# Send SIGTERM to all instances
for p in $all_pids; do
kill -TERM "$p" 2>/dev/null || true
done
# Wait up to 5s for graceful shutdown
for _ in {1..10}; do
kill -0 "$local_pid" 2>/dev/null || break
remaining="$(find_agent_pids "$id")"
[[ -z "$remaining" ]] && break
sleep 0.5
done
# SIGKILL si todavía sigue vivo
if kill -0 "$local_pid" 2>/dev/null; then
# SIGKILL any survivors
survivors="$(find_agent_pids "$id")"
if [[ -n "$survivors" ]]; then
warn "$id no respondió a SIGTERM, enviando SIGKILL..."
kill -9 "$local_pid" 2>/dev/null || true
for p in $survivors; do
kill -9 "$p" 2>/dev/null || true
done
fi
rm -f "$(pid_file "$id")"
ok "$id detenido (PID $local_pid)"
ok "$id detenido ($instance_count instance(s) stopped)"
((stopped++)) || true
done < <(list_agents_raw)