更新启动脚本

This commit is contained in:
2025-10-31 17:42:11 +08:00
parent e99d8f4914
commit 156a0e5752
3 changed files with 84 additions and 1 deletions

44
start_background.sh Normal file
View File

@@ -0,0 +1,44 @@
#!/bin/bash
# LiuBai网站后台启动脚本
PID_FILE="./liubai_web.pid"
LOG_FILE="./liubai_web.log"
# 检查是否已经在运行
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if kill -0 "$PID" 2>/dev/null; then
echo "服务已经在运行 (PID: $PID)"
exit 1
else
echo "删除旧的PID文件..."
rm -f "$PID_FILE"
fi
fi
echo "正在启动LiuBaiBlog网站服务器..."
# 使用nohup在后台运行
nohup python3 app.py > "$LOG_FILE" 2>&1 &
PID=$!
# 保存PID
echo $PID > "$PID_FILE"
echo "服务器已在后台启动!"
echo "PID: $PID"
echo "日志文件: $LOG_FILE"
echo "要停止服务,请运行: ./stop_background.sh"
# 等待一下确保服务器启动
sleep 2
# 检查进程是否还在运行
if kill -0 "$PID" 2>/dev/null; then
echo "服务器启动成功!"
else
echo "服务器启动失败,请检查日志文件: $LOG_FILE"
rm -f "$PID_FILE"
exit 1
fi