Commit d10c220c by imwangxiaozhou

fix(start.sh): 改进配置解析以精确读取指定节区

- 使用 sed 命令精确匹配 [sync] 和 [api] 节区,避免读取错误配置
- 使同步服务间隔时间可从 config.ini 动态配置,默认保持12小时
- 保持向后兼容性,当配置不存在时使用默认值
1 parent c6c7eabc
Showing 1 changed file with 10 additions and 4 deletions
...@@ -21,7 +21,13 @@ fi ...@@ -21,7 +21,13 @@ fi
if [ -f "$SYNC_PID" ] && ps -p $(cat "$SYNC_PID") > /dev/null 2>&1; then if [ -f "$SYNC_PID" ] && ps -p $(cat "$SYNC_PID") > /dev/null 2>&1; then
echo "警告: 同步服务已在运行 (PID: $(cat $SYNC_PID))。" echo "警告: 同步服务已在运行 (PID: $(cat $SYNC_PID))。"
else else
echo "正在启动定时同步服务 (每12小时一次)..." # 从 config.ini 中读取同步间隔
if [ -f "config.ini" ]; then
CONF_INTERVAL=$(sed -n '/^\[sync\]/,/^\[/p' config.ini | grep "^interval_hours =" | awk -F' = ' '{print $2}')
fi
INTERVAL=${CONF_INTERVAL:-12}
echo "正在启动定时同步服务 (每${INTERVAL}小时一次)..."
nohup python3 sync_data.py > "$SYNC_LOG" 2>&1 & nohup python3 sync_data.py > "$SYNC_LOG" 2>&1 &
echo $! > "$SYNC_PID" echo $! > "$SYNC_PID"
echo "同步服务已启动 (PID: $!)" echo "同步服务已启动 (PID: $!)"
...@@ -32,10 +38,10 @@ if [ -f "$API_PID" ] && ps -p $(cat "$API_PID") > /dev/null 2>&1; then ...@@ -32,10 +38,10 @@ if [ -f "$API_PID" ] && ps -p $(cat "$API_PID") > /dev/null 2>&1; then
echo "警告: API 服务已在运行 (PID: $(cat $API_PID))。" echo "警告: API 服务已在运行 (PID: $(cat $API_PID))。"
else else
echo "正在启动 API 接口服务 (FastAPI)..." echo "正在启动 API 接口服务 (FastAPI)..."
# 从 config.ini 中读取配置(简单解析) # 从 config.ini 中读取 API 配置(精确解析 [api] 节)
if [ -f "config.ini" ]; then if [ -f "config.ini" ]; then
CONF_PORT=$(grep "port =" config.ini | awk -F' = ' '{print $2}') CONF_PORT=$(sed -n '/^\[api\]/,/^\[/p' config.ini | grep "^port =" | awk -F' = ' '{print $2}')
CONF_HOST=$(grep "host =" config.ini | awk -F' = ' '{print $2}') CONF_HOST=$(sed -n '/^\[api\]/,/^\[/p' config.ini | grep "^host =" | awk -F' = ' '{print $2}')
fi fi
PORT=${CONF_PORT:-8000} PORT=${CONF_PORT:-8000}
HOST=${CONF_HOST:-0.0.0.0} HOST=${CONF_HOST:-0.0.0.0}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!