Files
agents_and_robots/dev-scripts/start.sh
T

74 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# start.sh — inicia uno o todos los agentes habilitados en background
#
# Uso:
# ./dev-scripts/start.sh # inicia todos los habilitados
# ./dev-scripts/start.sh assistant-bot # inicia uno específico
source "$(dirname "$0")/_common.sh"
load_env
TARGET="${1:-}"
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"
info "Iniciando $id..."
# 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
# Launch the compiled binary directly (no go run wrapper)
nohup "$bin" -c "$cfg" --log-level "${LOG_LEVEL:-info}" \
>> "$log" 2>&1 &
local pid=$!
echo "$pid" > "$pid_f"
# 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
}
started=0
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