Files
agents_and_robots/dev-scripts/start.sh
T
2026-03-04 00:59:10 +00:00

62 lines
1.5 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")"
info "Iniciando $id..."
# Lanza el launcher en background, desacoplado del terminal
nohup "$GO" run -tags goolm ./cmd/launcher -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
ok "$id PID $pid → 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
if is_running "$id"; then
warn "$id (ya corriendo, PID $(read_pid "$id"))"
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