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:
+36
-58
@@ -1,73 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
# start.sh — inicia uno o todos los agentes habilitados en background
|
||||
# start.sh — inicia el launcher unificado (todos los agentes habilitados)
|
||||
#
|
||||
# Uso:
|
||||
# ./dev-scripts/start.sh # inicia todos los habilitados
|
||||
# ./dev-scripts/start.sh assistant-bot # inicia uno específico
|
||||
# ./dev-scripts/start.sh # inicia el launcher unificado
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
load_env
|
||||
|
||||
TARGET="${1:-}"
|
||||
if is_launcher_running; then
|
||||
pid="$(read_launcher_pid)"
|
||||
fail "El launcher ya está corriendo (PID $pid). Usa restart.sh para reiniciar."
|
||||
fi
|
||||
|
||||
start_agent() {
|
||||
local id="$1" cfg="$2"
|
||||
local log; log="$(log_file "$id")"
|
||||
local pid_f; pid_f="$(pid_file "$id")"
|
||||
local bin="$REPO_ROOT/bin/launcher"
|
||||
BIN="$REPO_ROOT/bin/launcher"
|
||||
LOG="$(launcher_log_file)"
|
||||
PID_F="$(launcher_pid_file)"
|
||||
|
||||
info "Iniciando $id..."
|
||||
# Build if needed
|
||||
if [[ ! -x "$BIN" ]] || [[ "$(find ./cmd/launcher -newer "$BIN" 2>/dev/null | head -1)" ]]; then
|
||||
info "Ejecutando tests..."
|
||||
"$GO" test -tags goolm ./... || fail "Tests fallaron — corrige antes de compilar"
|
||||
|
||||
# Build the binary first to avoid go run wrapper PID issues
|
||||
if [[ ! -x "$bin" ]] || [[ "$(find ./cmd/launcher -newer "$bin" 2>/dev/null | head -1)" ]]; then
|
||||
info "Ejecutando tests..."
|
||||
"$GO" test -tags goolm ./... || {
|
||||
fail "$id tests fallaron — corrige antes de compilar"
|
||||
return 1
|
||||
}
|
||||
info "Compilando launcher..."
|
||||
mkdir -p "$(dirname "$bin")"
|
||||
"$GO" build -tags goolm -o "$bin" ./cmd/launcher || {
|
||||
fail "$id error de compilación — revisa el código"
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
info "Compilando launcher..."
|
||||
mkdir -p "$(dirname "$BIN")"
|
||||
"$GO" build -tags goolm -o "$BIN" ./cmd/launcher || fail "Error de compilación"
|
||||
fi
|
||||
|
||||
# Launch the compiled binary directly (no go run wrapper)
|
||||
nohup "$bin" -c "$cfg" --log-level "${LOG_LEVEL:-info}" \
|
||||
>> "$log" 2>&1 &
|
||||
info "Iniciando launcher unificado..."
|
||||
|
||||
local pid=$!
|
||||
echo "$pid" > "$pid_f"
|
||||
nohup "$BIN" --log-level "${LOG_LEVEL:-info}" \
|
||||
>> "$LOG" 2>&1 &
|
||||
|
||||
# Espera un momento y verifica que el proceso siga vivo
|
||||
sleep 1
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
local inst; inst="$(count_instances "$id")"
|
||||
ok "$id PID $pid (instances: $inst) → logs: $log"
|
||||
else
|
||||
rm -f "$pid_f"
|
||||
fail "$id arrancó pero murió — revisa: tail -f $log"
|
||||
fi
|
||||
}
|
||||
pid=$!
|
||||
echo "$pid" > "$PID_F"
|
||||
|
||||
started=0
|
||||
sleep 1
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
# Count enabled agents
|
||||
enabled=0
|
||||
total=0
|
||||
while IFS='|' read -r _id _v en _d _c; do
|
||||
((total++)) || true
|
||||
[[ "$en" == "true" ]] && ((enabled++)) || true
|
||||
done < <(list_agents_raw)
|
||||
|
||||
while IFS='|' read -r id version enabled desc cfg; do
|
||||
# Filtrar por TARGET si se especificó uno
|
||||
[[ -n "$TARGET" && "$id" != "$TARGET" ]] && continue
|
||||
|
||||
if [[ "$enabled" != "true" ]]; then
|
||||
warn "$id (disabled en config, saltar)"
|
||||
continue
|
||||
fi
|
||||
|
||||
start_agent "$id" "$cfg"
|
||||
((started++)) || true
|
||||
|
||||
done < <(list_agents_raw)
|
||||
|
||||
[[ "$started" -eq 0 && -z "$TARGET" ]] && warn "Ningún agente iniciado."
|
||||
[[ -n "$TARGET" && "$started" -eq 0 ]] && fail "Agente '$TARGET' no encontrado o ya está corriendo."
|
||||
|
||||
true
|
||||
ok "Launcher PID $pid ($enabled/$total agentes habilitados) → logs: $LOG"
|
||||
else
|
||||
rm -f "$PID_F"
|
||||
fail "Launcher arrancó pero murió — revisa: tail -f $LOG"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user