#!/bin/bash
# Life-OS nohup 启动脚本

cd /data/MBTI

# 停止旧服务
python stop.py 2>/dev/null || true

# 等待一下
sleep 2

# 使用 nohup 启动
nohup python start-nohup.py > logs/startup.log 2>&1 &

# 获取进程ID
PID=$!

echo "=========================================="
echo "🚀 Life-OS 正在后台启动..."
echo "=========================================="
echo ""
echo "启动脚本 PID: $PID"
echo "日志文件: logs/startup.log"
echo ""
echo "查看启动日志:"
echo "  tail -f logs/startup.log"
echo ""
echo "查看服务日志:"
echo "  tail -f logs/backend.log"
echo "  tail -f logs/frontend.log"
echo ""
echo "检查服务状态:"
echo "  ps aux | grep -E '(python.*main.py|next.*dev)'"
echo ""
echo "停止服务:"
echo "  python stop.py"
echo ""
echo "等待服务启动中..."
sleep 5

# 检查服务是否启动
if [ -f logs/backend.pid ] && [ -f logs/frontend.pid ]; then
    echo "✅ 服务启动成功！"
    echo ""
    echo "访问地址:"
    echo "  前端: http://localhost:3000"
    echo "  后端: http://localhost:8000"
    echo "  域名: https://zhshihe.cn"
else
    echo "⚠️  请检查日志文件确认服务状态"
fi

