feat: implement server-wide management actions and enhance TUI dashboard
This commit is contained in:
+22
-8
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user