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:
2026-03-06 09:06:11 +00:00
parent 1af0457c1f
commit b86da0b805
8 changed files with 265 additions and 307 deletions
+87 -72
View File
@@ -2,123 +2,138 @@
# server.sh — gestión unificada del servidor de bots
#
# Uso:
# ./dev-scripts/server.sh start [agent-id] # iniciar uno o todos
# ./dev-scripts/server.sh stop [agent-id] # detener uno o todos
# ./dev-scripts/server.sh restart [agent-id] # reiniciar uno o todos
# ./dev-scripts/server.sh status # resumen general del servidor
# ./dev-scripts/server.sh ps [agent-id] # procesos con detalle
# ./dev-scripts/server.sh logs [agent-id] # tail -f de logs
# ./dev-scripts/server.sh kill [agent-id] # SIGKILL forzado (emergencia)
# ./dev-scripts/server.sh dashboard # TUI interactivo
# ./dev-scripts/server.sh start # iniciar el launcher
# ./dev-scripts/server.sh stop # detener el launcher
# ./dev-scripts/server.sh restart # reiniciar el launcher
# ./dev-scripts/server.sh status # resumen general del servidor
# ./dev-scripts/server.sh ps # proceso con detalle
# ./dev-scripts/server.sh logs [lines] # tail -f de logs
# ./dev-scripts/server.sh kill # SIGKILL forzado (emergencia)
# ./dev-scripts/server.sh enable <id> # habilitar un agente
# ./dev-scripts/server.sh disable <id> # deshabilitar un agente
# ./dev-scripts/server.sh dashboard # TUI interactivo
source "$(dirname "$0")/_common.sh"
CMD="${1:-status}"
shift || true
AGENT="${1:-}"
ARG="${1:-}"
toggle_agent_enabled() {
local id="$1" value="$2"
for cfg in agents/*/config.yaml; do
[[ -f "$cfg" ]] || continue
local cid
cid=$(grep -m1 '^ id:' "$cfg" | awk '{print $2}')
if [[ "$cid" == "$id" ]]; then
sed -i "s/^\\( enabled:\\).*/\\1 $value/" "$cfg"
ok "$id enabled: $value"
info "Reinicia el launcher para aplicar: ./dev-scripts/server.sh restart"
return 0
fi
done
fail "Agente '$id' no encontrado"
}
case "$CMD" in
start)
exec "$REPO_ROOT/dev-scripts/start.sh" ${AGENT:+"$AGENT"}
exec "$REPO_ROOT/dev-scripts/start.sh"
;;
stop)
exec "$REPO_ROOT/dev-scripts/stop.sh" ${AGENT:+"$AGENT"}
exec "$REPO_ROOT/dev-scripts/stop.sh"
;;
restart)
exec "$REPO_ROOT/dev-scripts/restart.sh" ${AGENT:+"$AGENT"}
exec "$REPO_ROOT/dev-scripts/restart.sh"
;;
ps)
exec "$REPO_ROOT/dev-scripts/ps.sh" ${AGENT:+"$AGENT"}
exec "$REPO_ROOT/dev-scripts/ps.sh"
;;
logs)
exec "$REPO_ROOT/dev-scripts/logs.sh" ${AGENT:+"$AGENT"}
exec "$REPO_ROOT/dev-scripts/logs.sh" ${ARG:+"$ARG"}
;;
dashboard|tui)
exec "$REPO_ROOT/dev-scripts/dashboard.sh"
;;
kill)
# SIGKILL forzado para emergencias
if [[ -n "$AGENT" ]]; then
agents=("$AGENT")
else
agents=()
while IFS='|' read -r id _v _e _d _c; do
agents+=("$id")
done < <(list_agents_raw)
fi
enable)
[[ -n "$ARG" ]] || fail "Uso: $0 enable <agent-id>"
toggle_agent_enabled "$ARG" "true"
;;
killed=0
for id in "${agents[@]}"; do
all_pids="$(find_agent_pids "$id")"
if [[ -n "$all_pids" ]]; then
cnt="$(echo "$all_pids" | wc -l)"
for p in $all_pids; do
kill -9 "$p" 2>/dev/null || true
done
rm -f "$(pid_file "$id")"
ok "$id killed ($cnt instance(s), PIDs: $(echo $all_pids | tr '\n' ' '))"
((killed++)) || true
else
dim " $id (no estaba corriendo)"
fi
done
[[ "$killed" -eq 0 ]] && dim "Ningún proceso eliminado."
disable)
[[ -n "$ARG" ]] || fail "Uso: $0 disable <agent-id>"
toggle_agent_enabled "$ARG" "false"
;;
kill)
if ! is_launcher_running; then
dim " El launcher no está corriendo."
exit 0
fi
pid="$(read_launcher_pid)"
kill -9 "$pid" 2>/dev/null || true
rm -f "$(launcher_pid_file)"
ok "Launcher killed (PID $pid)"
;;
status)
# Resumen general del servidor
total=0
running=0
stopped=0
disabled=0
while IFS='|' read -r id _version enabled _desc _cfg; do
((total++)) || true
st=$(agent_status "$id" "$enabled")
case "$st" in
running) ((running++)) || true ;;
stopped) ((stopped++)) || true ;;
disabled) ((disabled++)) || true ;;
esac
done < <(list_agents_raw)
echo ""
echo -e " ${BLU}Bot Server Status${RST}"
printf '%s\n' " $(printf '─%.0s' {1..40})"
echo -e " Agentes totales: $total"
echo -e " ${GRN}● Running:${RST} $running"
echo -e " ${DIM}○ Stopped:${RST} $stopped"
echo -e " ${YLW} Disabled:${RST} $disabled"
if is_launcher_running; then
pid="$(read_launcher_pid)"
echo -e " ${GRN}● Launcher running${RST} PID $pid"
else
echo -e " ${DIM}○ Launcher stopped${RST}"
fi
echo ""
enabled=0
disabled=0
total=0
while IFS='|' read -r id _v en _d _c; do
((total++)) || true
if [[ "$en" == "true" ]]; then
((enabled++)) || true
else
((disabled++)) || true
fi
done < <(list_agents_raw)
echo -e " Agentes totales: $total"
echo -e " ${GRN}● Enabled:${RST} $enabled"
echo -e " ${DIM}○ Disabled:${RST} $disabled"
echo ""
# Mostrar tabla de agentes
"$REPO_ROOT/dev-scripts/list.sh"
# Si hay agentes corriendo, mostrar uso de recursos
if [[ "$running" -gt 0 ]]; then
if is_launcher_running; then
echo ""
"$REPO_ROOT/dev-scripts/ps.sh"
fi
;;
*)
echo "Uso: $0 {start|stop|restart|status|ps|logs|kill|dashboard} [agent-id]"
echo "Uso: $0 {start|stop|restart|status|ps|logs|kill|enable|disable|dashboard}"
echo ""
echo "Comandos:"
echo " start [id] Iniciar uno o todos los agentes habilitados"
echo " stop [id] Detener uno o todos los agentes"
echo " restart [id] Reiniciar uno o todos los agentes"
echo " status Resumen general del servidor"
echo " ps [id] Procesos corriendo con detalle (PID, mem, CPU)"
echo " logs [id] Tail -f de logs"
echo " kill [id] SIGKILL forzado (solo emergencias)"
echo " dashboard TUI interactivo de gestión"
echo " start Iniciar el launcher unificado"
echo " stop Detener el launcher"
echo " restart Reiniciar el launcher"
echo " status Resumen general del servidor"
echo " ps Proceso del launcher con detalle (PID, mem, CPU)"
echo " logs [lines] Tail -f de logs del launcher"
echo " kill SIGKILL forzado (solo emergencias)"
echo " enable <id> Habilitar un agente (requiere restart)"
echo " disable <id> Deshabilitar un agente (requiere restart)"
echo " dashboard TUI interactivo de gestión"
exit 1
;;
esac