if [ -n "$old_pids" ]; then echo"发现旧进程 PID: $old_pids,正在终止..." | tee -a "$LOG_FILE" kill$old_pids sleep 2 # 确认是否成功终止 for pid in$old_pids; do if ps -p $pid > /dev/null; then echo"进程 $pid 未能终止,强制杀掉..." | tee -a "$LOG_FILE" kill -9 $pid fi done push_to_feishu "旧服务已停止" else echo"未找到旧服务进程,无需停止。" | tee -a "$LOG_FILE" push_to_feishu "未找到旧服务进程" fi }
if [ -f "$REQ_FILE" ]; then echo"检测到 requirements.txt,开始安装依赖..." | tee -a "$LOG_FILE" push_to_feishu "开始安装 Python 依赖..."
$PYTHON_EXEC -m ensurepip --upgrade 2>&1 | tee -a "$LOG_FILE" $PYTHON_EXEC -m pip install --upgrade pip 2>&1 | tee -a "$LOG_FILE" $PYTHON_EXEC -m pip install -r "$REQ_FILE" 2>&1 | tee -a "$LOG_FILE" status=${PIPESTATUS[0]}# 从 pipe 中正确获取 pip install 的退出状态
if [ $status -eq 0 ]; then echo"依赖安装完成" | tee -a "$LOG_FILE" push_to_feishu "依赖安装完成" else echo"依赖安装失败,状态码:$status" | tee -a "$LOG_FILE" push_to_feishu "依赖安装失败,状态码:$status" exit 1 fi else echo"未找到 requirements.txt,跳过依赖安装" | tee -a "$LOG_FILE" push_to_feishu "未找到 requirements.txt,跳过依赖安装" fi