mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-10 00:40:30 +08:00
feat: robust stop-all (pgrep kill) + start-all skip-if-running detection
Former-commit-id: 6ffcf5714ef663afa22f891bdb566950e4c47b60
This commit is contained in:
@@ -12,6 +12,11 @@ start_service() {
|
|||||||
local name="$1"; local jar="$2"; local port="$3"
|
local name="$1"; local jar="$2"; local port="$3"
|
||||||
local opts="${4:-$JAVA_OPTS_LIGHT}"; shift 4
|
local opts="${4:-$JAVA_OPTS_LIGHT}"; shift 4
|
||||||
|
|
||||||
|
if pgrep -f "$(basename "$jar")" >/dev/null 2>&1; then
|
||||||
|
log_warn " $name already running ($(pgrep -f "$(basename "$jar")" | tr '\n' ' ')) — skipping"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
log_info "Starting $name (port $port)..."
|
log_info "Starting $name (port $port)..."
|
||||||
|
|
||||||
if [[ ! -f "$jar" ]]; then
|
if [[ ! -f "$jar" ]]; then
|
||||||
|
|||||||
@@ -1,22 +1,56 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# stop-all.sh — 按逆序停止所有服务
|
# stop-all.sh — 停止所有 V2 测试环境服务 (PID 文件 + 进程名匹配)
|
||||||
source "$(dirname "${BASH_SOURCE[0]}")/config/env.sh"
|
source "$(dirname "${BASH_SOURCE[0]}")/config/env.sh"
|
||||||
|
|
||||||
log_info "Stopping all services..."
|
log_info "Stopping all services..."
|
||||||
|
|
||||||
|
# 1. Stop by PID files
|
||||||
for pid_file in "$LOG_DIR"/*.pid; do
|
for pid_file in "$LOG_DIR"/*.pid; do
|
||||||
if [[ -f "$pid_file" ]]; then
|
if [[ -f "$pid_file" ]]; then
|
||||||
pid=$(cat "$pid_file")
|
pid=$(cat "$pid_file")
|
||||||
svc=$(basename "$pid_file" .pid)
|
svc=$(basename "$pid_file" .pid)
|
||||||
if kill -0 "$pid" 2>/dev/null; then
|
if kill -0 "$pid" 2>/dev/null; then
|
||||||
log_info "Stopping $svc (pid=$pid)..."
|
log_info "Stopping $svc (pid=$pid)..."
|
||||||
kill "$pid"
|
kill "$pid" 2>/dev/null || true
|
||||||
sleep 2
|
sleep 2
|
||||||
kill -9 "$pid" 2>/dev/null || true
|
kill -9 "$pid" 2>/dev/null || true
|
||||||
log_ok " $svc stopped"
|
log_ok " $svc stopped"
|
||||||
|
else
|
||||||
|
log_info " $svc already dead (pid=$pid)"
|
||||||
fi
|
fi
|
||||||
rm -f "$pid_file"
|
rm -f "$pid_file"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# 2. Kill any remaining Java processes by name pattern
|
||||||
|
KILL_PATTERNS=(
|
||||||
|
"cw-elevator-application"
|
||||||
|
"ninca-crk-std-backend"
|
||||||
|
"ninca-qk-alarm-app"
|
||||||
|
"ninca-common"
|
||||||
|
"component-organization"
|
||||||
|
"cwos-portal"
|
||||||
|
"cwos-manager"
|
||||||
|
"cwos-system-api"
|
||||||
|
)
|
||||||
|
|
||||||
|
for pattern in "${KILL_PATTERNS[@]}"; do
|
||||||
|
pids=$(pgrep -f "$pattern" 2>/dev/null || true)
|
||||||
|
if [[ -n "$pids" ]]; then
|
||||||
|
for pid in $pids; do
|
||||||
|
log_info "Killing $pattern (pid=$pid)..."
|
||||||
|
kill "$pid" 2>/dev/null || true
|
||||||
|
sleep 1
|
||||||
|
kill -9 "$pid" 2>/dev/null || true
|
||||||
|
done
|
||||||
|
log_ok " $pattern cleaned up"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# 3. Stop Docker containers
|
||||||
|
log_info "Stopping Docker containers..."
|
||||||
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||||
|
docker compose -f docker-compose.infra.yml down 2>/dev/null || true
|
||||||
|
log_ok " Docker containers stopped"
|
||||||
|
|
||||||
log_info "All services stopped"
|
log_info "All services stopped"
|
||||||
|
|||||||
Reference in New Issue
Block a user