mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 08:20:31 +08:00
feat: add service start/stop orchestration scripts
Former-commit-id: 4e4335591be6f906229115cef4fe9c42c11d70f1
This commit is contained in:
Executable
+83
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
# start-all.sh — 按拓扑序启动所有 Java 服务
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/config/env.sh"
|
||||
export JAVA_HOME
|
||||
export PATH="$JAVA_HOME/bin:$PATH"
|
||||
|
||||
log_info "Phase 5: Starting all services..."
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
# 启动函数: start_service <name> <jar_path> <port> <java_opts> <extra_args>
|
||||
start_service() {
|
||||
local name="$1"; local jar="$2"; local port="$3"
|
||||
local opts="${4:-$JAVA_OPTS_LIGHT}"; shift 4
|
||||
|
||||
log_info "Starting $name (port $port)..."
|
||||
|
||||
if [[ ! -f "$jar" ]]; then
|
||||
log_error " JAR not found: $jar"
|
||||
return 1
|
||||
fi
|
||||
|
||||
nohup $JAVA -jar $opts "$jar" "$@" \
|
||||
--spring.config.location="$(dirname "$jar")/" \
|
||||
> "$LOG_DIR/${name}.log" 2>&1 &
|
||||
|
||||
local pid=$!
|
||||
echo $pid > "$LOG_DIR/${name}.pid"
|
||||
|
||||
# 等待服务就绪 (最多 60s)
|
||||
for i in $(seq 1 30); do
|
||||
sleep 2
|
||||
if curl -sf "http://127.0.0.1:$port/actuator/health" &>/dev/null; then
|
||||
log_ok " $name (pid=$pid, port=$port) STARTED"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
log_warn " $name health check timeout after 60s (pid=$pid)"
|
||||
return 1
|
||||
}
|
||||
|
||||
# ============================================
|
||||
# 启动顺序 (拓扑序)
|
||||
# ============================================
|
||||
|
||||
# A1: ninca-common
|
||||
COMMON_JAR=$(find "$SERVICE_DIR/ninca-common" -name "*.jar" -not -name "*-sources*" 2>/dev/null | head -1)
|
||||
if [[ -n "$COMMON_JAR" ]]; then
|
||||
start_service "ninca-common" "$COMMON_JAR" "$PORT_NINCA_COMMON" "$JAVA_OPTS_LIGHT"
|
||||
fi
|
||||
|
||||
# A2: component-organization
|
||||
ORG_JAR=$(find "$SERVICE_DIR/component-org" -name "*.jar" -not -name "*-sources*" 2>/dev/null | head -1)
|
||||
if [[ -n "$ORG_JAR" ]]; then
|
||||
start_service "component-org" "$ORG_JAR" "$PORT_COMPONENT_ORG" "$JAVA_OPTS_LIGHT"
|
||||
fi
|
||||
|
||||
# A10: CRK-std
|
||||
CRK_DIR="$STAR_CENTER/ninca_crk_std_01-ninca_crk_std_backend/ninca-crk-std-backend-V2.9.2_20210730"
|
||||
CRK_JAR="$STAR_CENTER/ninca_crk_std_01-ninca_crk_std_backend/ninca-crk-std-backend-V2.9.2_20210730.jar"
|
||||
if [[ -f "$CRK_JAR" ]]; then
|
||||
start_service "crk-std" "$CRK_JAR" "$PORT_CRK_STD" "$JAVA_OPTS_HEAVY" --spring.config.location="$CRK_DIR/"
|
||||
fi
|
||||
|
||||
# A11: alarm-app
|
||||
ALARM_JAR="$STAR_CENTER/ninca_qk_alarm_app_01-ninca_qk_alarm_app/ninca-qk-alarm-app-V2.9.2_20210730.jar"
|
||||
if [[ -f "$ALARM_JAR" ]]; then
|
||||
start_service "alarm-app" "$ALARM_JAR" "$PORT_ALARM" "$JAVA_OPTS_HEAVY" --spring.config.location="$STAR_CENTER/ninca_qk_alarm_app_01-ninca_qk_alarm_app/"
|
||||
fi
|
||||
|
||||
# A12: elevator V2 (最后启动)
|
||||
ELEVATOR_V2_JAR="$REPO_ROOT/maven-cw-elevator-application/deploy/v2-maven/cw-elevator-application-2.0.7.jar"
|
||||
if [[ -f "$ELEVATOR_V2_JAR" ]]; then
|
||||
start_service "elevator-v2" "$ELEVATOR_V2_JAR" "$PORT_ELEVATOR_V2" "$JAVA_OPTS_HEAVY" --spring.config.location="$REPO_ROOT/maven-cw-elevator-application/deploy/v2-maven/"
|
||||
fi
|
||||
|
||||
# A13: elevator V1 (对拍对照)
|
||||
ELEVATOR_V1_JAR="$REPO_ROOT/maven-cw-elevator-application/deploy/v1-legacy/cw-elevator-application-V1.0.0.20211103.jar"
|
||||
if [[ -f "$ELEVATOR_V1_JAR" ]]; then
|
||||
start_service "elevator-v1" "$ELEVATOR_V1_JAR" "$PORT_ELEVATOR_V1" "$JAVA_OPTS_HEAVY" --spring.config.location="$REPO_ROOT/maven-cw-elevator-application/deploy/v1-legacy/"
|
||||
fi
|
||||
|
||||
log_info "All services started"
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
+# stop-all.sh — 按逆序停止所有服务
|
||||
+source "$(dirname "${BASH_SOURCE[0]}")/config/env.sh"
|
||||
+
|
||||
+log_info "Stopping all services..."
|
||||
+
|
||||
+for pid_file in "$LOG_DIR"/*.pid; do
|
||||
+ if [[ -f "$pid_file" ]]; then
|
||||
+ pid=$(cat "$pid_file")
|
||||
+ svc=$(basename "$pid_file" .pid)
|
||||
+ if kill -0 "$pid" 2>/dev/null; then
|
||||
+ log_info "Stopping $svc (pid=$pid)..."
|
||||
+ kill "$pid"
|
||||
+ sleep 2
|
||||
+ kill -9 "$pid" 2>/dev/null || true
|
||||
+ log_ok " $svc stopped"
|
||||
+ fi
|
||||
+ rm -f "$pid_file"
|
||||
+ fi
|
||||
+done
|
||||
+
|
||||
+log_info "All services stopped"
|
||||
Reference in New Issue
Block a user