auto_trade_sys/backend/restart.sh
薇薇安 ec54716266 1
2026-02-08 20:33:37 +08:00

34 lines
855 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 重启后端服务脚本
cd "$(dirname "$0")"
# 查找运行中的uvicorn进程 (优先使用 lsof 查找端口占用)
PID=$(lsof -t -i:8001)
if [ -z "$PID" ]; then
# 回退到 ps 查找 (如果 lsof 没找到或不可用)
PID=$(ps aux | grep "uvicorn api.main:app" | grep -v grep | awk '{print $2}')
fi
if [ -z "$PID" ]; then
echo "未找到运行中的后端服务"
echo "启动新服务..."
./start.sh
else
echo "找到运行中的后端服务PID: $PID"
echo "正在停止服务..."
kill $PID
sleep 2
# 检查是否成功停止 (使用 kill -0 检查进程是否存在,替代 ps -p)
if kill -0 $PID > /dev/null 2>&1; then
echo "强制停止服务..."
kill -9 $PID
sleep 1
fi
echo "服务已停止,正在启动新服务..."
./start.sh
fi