refactor: update dev-scripts for unified launcher model
Actualiza todos los scripts de desarrollo para el modelo de launcher unificado. Ya no se inician procesos individuales por agente — un solo proceso corre todos. _common.sh: helpers para launcher unificado (is_launcher_running, read_launcher_pid, launcher_pid_file/log_file), agent_status() ahora deriva estado del launcher start.sh: inicia el launcher unificado (sin -c flag, descubre todos los agentes) stop.sh: detiene el launcher unificado restart.sh: stop + start del launcher ps.sh: muestra stats del proceso launcher + lista de agentes enabled/disabled logs.sh: tail -f del log unificado del launcher server.sh: añade comandos enable/disable para gestionar agentes, elimina start/stop por agente remove.sh: simplificado a toggle enabled:false + sugerencia de restart Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+21
-48
@@ -1,59 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# stop.sh — detiene uno o todos los agentes en ejecución
|
||||
# stop.sh — detiene el launcher unificado
|
||||
#
|
||||
# Uso:
|
||||
# ./dev-scripts/stop.sh # detiene todos los que estén corriendo
|
||||
# ./dev-scripts/stop.sh assistant-bot # detiene uno específico
|
||||
# ./dev-scripts/stop.sh
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
|
||||
TARGET="${1:-}"
|
||||
stopped=0
|
||||
if ! is_launcher_running; then
|
||||
dim " El launcher no está corriendo."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while IFS='|' read -r id _version _enabled _desc _cfg; do
|
||||
[[ -n "$TARGET" && "$id" != "$TARGET" ]] && continue
|
||||
pid="$(read_launcher_pid)"
|
||||
info "Deteniendo launcher (PID $pid)..."
|
||||
|
||||
if ! is_running "$id"; then
|
||||
dim " $id (no está corriendo)"
|
||||
continue
|
||||
fi
|
||||
kill -TERM "$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)"
|
||||
# Wait up to 5s for graceful shutdown
|
||||
for _ in {1..10}; do
|
||||
kill -0 "$pid" 2>/dev/null || break
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
if [[ "$instance_count" -gt 1 ]]; then
|
||||
warn "$id has $instance_count instances running — stopping all"
|
||||
fi
|
||||
# SIGKILL if still alive
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
warn "Launcher no respondió a SIGTERM, enviando SIGKILL..."
|
||||
kill -9 "$pid" 2>/dev/null || true
|
||||
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
|
||||
remaining="$(find_agent_pids "$id")"
|
||||
[[ -z "$remaining" ]] && break
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
# SIGKILL any survivors
|
||||
survivors="$(find_agent_pids "$id")"
|
||||
if [[ -n "$survivors" ]]; then
|
||||
warn "$id no respondió a SIGTERM, enviando SIGKILL..."
|
||||
for p in $survivors; do
|
||||
kill -9 "$p" 2>/dev/null || true
|
||||
done
|
||||
fi
|
||||
|
||||
rm -f "$(pid_file "$id")"
|
||||
ok "$id detenido ($instance_count instance(s) stopped)"
|
||||
((stopped++)) || true
|
||||
|
||||
done < <(list_agents_raw)
|
||||
|
||||
[[ "$stopped" -eq 0 && -z "$TARGET" ]] && dim "Ningún agente estaba corriendo."
|
||||
[[ -n "$TARGET" && "$stopped" -eq 0 ]] && fail "Agente '$TARGET' no encontrado o no estaba corriendo."
|
||||
|
||||
true
|
||||
rm -f "$(launcher_pid_file)"
|
||||
ok "Launcher detenido"
|
||||
|
||||
Reference in New Issue
Block a user