2a37a4ffbf
Equivalentes .command (doble-clic en Finder) de los .bat de Windows: - setup_mac.command: bootstrap con un click (detecta Python 3.10+, crea .venv, instala requirements + Chromium de Playwright, copia .env.example -> .env). - start/stop/restart/start_persistent_profile.command: espejo de los .bat, lanzan el server con nohup usando el python del .venv. - mp_common.sh: helper compartido (raíz, venv, banners). runtime_control.py ahora es cross-platform (IS_WINDOWS): lsof/ps/pgrep/kill en POSIX, netstat/PowerShell/taskkill en Windows. _kill_tree_posix mata el árbol padre+worker de uvicorn con SIGTERM. .venv/ añadido a .gitignore. Docs actualizadas (CLAUDE.md, AGENTS.md, PLAYWRIGHT_SESSION.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
2.9 KiB
Bash
Executable File
79 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ---------------------------------------------------------------------------
|
|
# restart.command — Equivalente macOS/Linux de restart.bat.
|
|
# Reinicia el servidor detectando automáticamente si estaba en modo normal o
|
|
# perfil persistente (lee generated/runtime/last_mode), mata Chromium zombies
|
|
# de Playwright y limpia batch files huérfanos.
|
|
# ---------------------------------------------------------------------------
|
|
set -euo pipefail
|
|
source "$(dirname "${BASH_SOURCE[0]}")/mp_common.sh"
|
|
|
|
banner "MP Manager - Reiniciando Servidor"
|
|
|
|
PY="$(require_venv)" || { hold_window; exit 1; }
|
|
|
|
# --- 1. Determinar modo activo (normal / persistent) ----------------------
|
|
MODE="normal"
|
|
LAST_MODE_FILE="generated/runtime/last_mode"
|
|
if [ -f "$LAST_MODE_FILE" ]; then
|
|
MODE="$(tr -d '[:space:]' < "$LAST_MODE_FILE")"
|
|
fi
|
|
if [ "$MODE" != "normal" ] && [ "$MODE" != "persistent" ]; then
|
|
MODE="normal"
|
|
fi
|
|
info "Modo detectado: $MODE"
|
|
|
|
# --- 2. Detener el server actual de forma segura --------------------------
|
|
set +e
|
|
"$PY" runtime_control.py stop --force
|
|
set -e
|
|
|
|
# --- 3. Limpiar Chromium headless huérfanos de Playwright -----------------
|
|
# Solo matamos procesos cuya línea de comando apunta al Chromium de Playwright
|
|
# (ms-playwright / chrome-headless-shell), NUNCA el Google Chrome del usuario.
|
|
info "Limpiando zombies de Chromium headless de Playwright si los hay..."
|
|
pkill -f "ms-playwright.*[Cc]hromium" 2>/dev/null || true
|
|
pkill -f "chrome-headless-shell" 2>/dev/null || true
|
|
|
|
# --- 4. Limpiar batch files interrumpidos del runtime ---------------------
|
|
if compgen -G "generated/runtime/batch/_bulk_batch_*.json" >/dev/null; then
|
|
info "Limpiando batch files huérfanos..."
|
|
rm -f generated/runtime/batch/_bulk_batch_*.json
|
|
fi
|
|
rm -f generated/runtime/batch/_test_batch.json 2>/dev/null || true
|
|
|
|
# --- 5. Pequeña espera para liberar el puerto -----------------------------
|
|
info "Esperando 2 segundos para liberar puerto..."
|
|
sleep 2
|
|
|
|
# --- 6. Relanzar en el modo correcto --------------------------------------
|
|
mkdir -p generated/runtime generated/logs
|
|
LOG="$PROJECT_DIR/generated/logs/server.out"
|
|
|
|
if [ "$MODE" = "persistent" ]; then
|
|
export GHL_BROWSER_PROFILE_DIR="$PROJECT_DIR/generated/browser/profile"
|
|
info "Relanzando en modo PERFIL PERSISTENTE."
|
|
info "GHL_BROWSER_PROFILE_DIR=$GHL_BROWSER_PROFILE_DIR"
|
|
if [ ! -d "$GHL_BROWSER_PROFILE_DIR" ]; then
|
|
echo
|
|
warn "El perfil persistente aún no existe."
|
|
warn 'Cuando arranque, usa "Renovar sesión Bucéfalo" en el dashboard.'
|
|
echo
|
|
fi
|
|
echo "persistent" > "$LAST_MODE_FILE"
|
|
else
|
|
info "Relanzando en modo NORMAL."
|
|
echo "normal" > "$LAST_MODE_FILE"
|
|
fi
|
|
|
|
nohup "$PY" "$PROJECT_DIR/main.py" >> "$LOG" 2>&1 &
|
|
disown || true
|
|
|
|
echo
|
|
echo "==================================================="
|
|
echo " Servidor reiniciado en modo $MODE."
|
|
echo " Logs: generated/logs/server.out"
|
|
echo " Para detener: stop.command"
|
|
echo "==================================================="
|
|
hold_window
|