#!/usr/bin/env bash set -euo pipefail PROJECT_DIR="/home/long/project/蚊子" STATE_DIR="$PROJECT_DIR/logs/e2e-automation" PID_FILE="$STATE_DIR/runner.pid" echo "[e2e_stop] Starting stop procedure..." # Function to kill process safely kill_process() { local pid="$1" local name="$2" if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then echo "[e2e_stop] Terminating $name (PID: $pid)..." kill "$pid" 2>/dev/null || true sleep 1 # Force kill if still alive if kill -0 "$pid" 2>/dev/null; then echo "[e2e_stop] Force killing $name (PID: $pid)..." kill -9 "$pid" 2>/dev/null || true fi echo "[e2e_stop] $name terminated" else echo "[e2e_stop] $name not running or already stopped" fi } # Read PID from file if exists if [ -f "$PID_FILE" ]; then PID=$(cat "$PID_FILE") kill_process "$PID" "runner from pid file" fi # Also check for any orphaned runner processes ORPHAN_PIDS=$(pgrep -f "e2e_continuous_runner.sh" 2>/dev/null || true) if [ -n "$ORPHAN_PIDS" ]; then echo "[e2e_stop] Found orphaned runner processes: $ORPHAN_PIDS" for pid in $ORPHAN_PIDS; do kill_process "$pid" "orphaned runner" done fi # Clean up pid file if [ -f "$PID_FILE" ]; then rm -f "$PID_FILE" echo "[e2e_stop] Removed pid file" fi # Remove done flag if exists if [ -f "$STATE_DIR/done.flag" ]; then rm -f "$STATE_DIR/done.flag" echo "[e2e_stop] Removed done flag" fi echo "[e2e_stop] Stop procedure completed" exit 0