Commit 2d1705c6 by imwangxiaozhou

feat(scripts): 新增品牌同步服务支持并优化服务管理脚本

新增品牌同步服务的全流程支持,具体修改包括:
1. 为三个管理脚本添加品牌同步服务的进程文件配置
2. 重构start.sh,提取通用启动函数统一服务启动逻辑
3. 更新服务名称描述,将原同步服务更名为门店同步服务
4. 为所有服务添加日志重定向,将运行日志保存至logs目录
1 parent 22d23913
......@@ -3,6 +3,7 @@
cd "$(dirname "$0")/.."
SYNC_PID="sync.pid"
BRAND_SYNC_PID="brand_sync.pid"
API_PID="api.pid"
echo "=== 门店管理服务启动脚本 ==="
......@@ -12,19 +13,24 @@ if [ -f "requirements.txt" ]; then
pip3.10 install -r requirements.txt > /dev/null 2>&1
fi
if [ -f "$SYNC_PID" ] && ps -p $(cat "$SYNC_PID") > /dev/null 2>&1; then
echo "警告: 同步服务已在运行 (PID: $(cat $SYNC_PID))。"
else
if [ -f "config.ini" ]; then
CONF_INTERVAL=$(sed -n '/^\[sync\]/,/^\[/p' config.ini | grep "^interval_hours =" | awk -F' = ' '{print $2}')
start_service() {
local pid_file=$1
local name=$2
local cmd=$3
local log_file=$4
if [ -f "$pid_file" ] && ps -p $(cat "$pid_file") > /dev/null 2>&1; then
echo "警告: $name 已在运行 (PID: $(cat $pid_file))。"
else
echo "正在启动 $name ..."
nohup $cmd > "$log_file" 2>&1 &
echo $! > "$pid_file"
echo "$name 已启动 (PID: $!)"
fi
INTERVAL=${CONF_INTERVAL:-12}
}
echo "正在启动定时同步服务 (每${INTERVAL}小时一次)..."
nohup python3 bin/run_sync.py > /dev/null 2>&1 &
echo $! > "$SYNC_PID"
echo "同步服务已启动 (PID: $!)"
fi
start_service "$SYNC_PID" "门店同步服务" "python3 bin/run_sync.py" "logs/startup_sync.log"
start_service "$BRAND_SYNC_PID" "品牌同步服务" "python3 bin/run_brand_sync.py" "logs/startup_brand_sync.log"
if [ -f "$API_PID" ] && ps -p $(cat "$API_PID") > /dev/null 2>&1; then
echo "警告: API 服务已在运行 (PID: $(cat $API_PID))。"
......@@ -38,7 +44,7 @@ else
HOST=${CONF_HOST:-0.0.0.0}
echo "配置信息: $HOST:$PORT"
nohup python3 bin/run_api.py --server --host "$HOST" --port "$PORT" > /dev/null 2>&1 &
nohup python3 bin/run_api.py --server --host "$HOST" --port "$PORT" > "logs/startup_api.log" 2>&1 &
echo $! > "$API_PID"
echo "API 服务已启动 (PID: $!)"
fi
......
......@@ -3,6 +3,7 @@
cd "$(dirname "$0")/.."
SYNC_PID="sync.pid"
BRAND_SYNC_PID="brand_sync.pid"
API_PID="api.pid"
echo "=== 门店管理服务状态检查 ==="
......@@ -26,5 +27,6 @@ check_status() {
echo ""
}
check_status "$SYNC_PID" "同步服务"
check_status "$SYNC_PID" "门店同步服务"
check_status "$BRAND_SYNC_PID" "品牌同步服务"
check_status "$API_PID" "API 服务"
......@@ -3,6 +3,7 @@
cd "$(dirname "$0")/.."
SYNC_PID="sync.pid"
BRAND_SYNC_PID="brand_sync.pid"
API_PID="api.pid"
echo "=== 门店管理服务停止脚本 ==="
......@@ -36,7 +37,8 @@ stop_process() {
rm "$pid_file"
}
stop_process "$SYNC_PID" "同步服务"
stop_process "$SYNC_PID" "门店同步服务"
stop_process "$BRAND_SYNC_PID" "品牌同步服务"
stop_process "$API_PID" "API 服务"
echo "清理完成。"
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!