Files
weibo_signin/start_linux.sh

106 lines
3.1 KiB
Bash
Raw Permalink Normal View History

2026-03-17 09:41:37 +08:00
#!/bin/bash
# ============================================================
# Weibo-HotSign Linux 启动脚本
# 使用方式: chmod +x start_linux.sh && ./start_linux.sh
# ============================================================
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
PID_DIR="${PROJECT_DIR}/.pids"
LOG_DIR="${PROJECT_DIR}/logs"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[✓]${NC} $1"; }
warn() { echo -e "${YELLOW}[!]${NC} $1"; }
error() { echo -e "${RED}[✗]${NC} $1"; exit 1; }
# 创建目录
mkdir -p "$PID_DIR" "$LOG_DIR"
# 检查是否已在运行
check_running() {
local name=$1
local pidfile="${PID_DIR}/${name}.pid"
if [ -f "$pidfile" ]; then
local pid=$(cat "$pidfile")
if kill -0 "$pid" 2>/dev/null; then
warn "${name} 已在运行 (PID: ${pid}),跳过"
return 0
else
rm -f "$pidfile"
fi
fi
return 1
}
echo ""
echo "========================================"
echo " Weibo-HotSign 启动服务"
echo "========================================"
echo ""
# ------ 1. 启动 Auth Service (端口 8001) ------
if ! check_running "auth_service"; then
info "启动 Auth Service (端口 8001)..."
source "${PROJECT_DIR}/backend/venv/bin/activate"
cd "${PROJECT_DIR}/backend"
PYTHONPATH="${PROJECT_DIR}/backend" nohup python -m uvicorn auth_service.app.main:app \
--host 0.0.0.0 --port 8001 \
> "${LOG_DIR}/auth_service.log" 2>&1 &
echo $! > "${PID_DIR}/auth_service.pid"
deactivate
cd "${PROJECT_DIR}"
sleep 2
info "Auth Service 已启动 (PID: $(cat ${PID_DIR}/auth_service.pid))"
fi
# ------ 2. 启动 API Service (端口 8000) ------
if ! check_running "api_service"; then
info "启动 API Service (端口 8000)..."
source "${PROJECT_DIR}/backend/venv/bin/activate"
cd "${PROJECT_DIR}/backend"
PYTHONPATH="${PROJECT_DIR}/backend" nohup python -m uvicorn api_service.app.main:app \
--host 0.0.0.0 --port 8000 \
> "${LOG_DIR}/api_service.log" 2>&1 &
echo $! > "${PID_DIR}/api_service.pid"
deactivate
cd "${PROJECT_DIR}"
sleep 2
info "API Service 已启动 (PID: $(cat ${PID_DIR}/api_service.pid))"
fi
# ------ 3. 启动 Frontend (端口 5000) ------
if ! check_running "frontend"; then
info "启动 Frontend (端口 5000)..."
source "${PROJECT_DIR}/frontend/venv/bin/activate"
cd "${PROJECT_DIR}/frontend"
nohup python app.py \
> "${LOG_DIR}/frontend.log" 2>&1 &
echo $! > "${PID_DIR}/frontend.pid"
deactivate
cd "${PROJECT_DIR}"
sleep 2
info "Frontend 已启动 (PID: $(cat ${PID_DIR}/frontend.pid))"
fi
echo ""
echo "========================================"
echo " 所有服务已启动"
echo "========================================"
echo ""
echo " 前端界面: http://localhost:5000"
echo " API Service: http://localhost:8000"
echo " Auth Service: http://localhost:8001"
echo ""
echo " 日志目录: ${LOG_DIR}/"
echo " 停止服务: ./stop_linux.sh"
echo " 查看日志: tail -f logs/auth_service.log"
echo ""