81 lines
2.2 KiB
Bash
Executable File
81 lines
2.2 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"
|
|
|
|
# Check for duplicate instances already running
|
|
local existing; existing="$(count_instances "$id")"
|
|
if [[ "$existing" -gt 0 ]]; then
|
|
warn "$id already has $existing instance(s) running (orphan processes?)"
|
|
warn " Run ./dev-scripts/stop.sh $id first to clean up"
|
|
return 1
|
|
fi
|
|
|
|
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 "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
|
|
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
|