让我回顾一下刚才做的关键操作:

🔧 我做的关键操作
1. 发现服务自动退出的问题
之前用 nohup 和后台方式启动 CoPaw 时,服务启动几秒后就自动关闭了:
INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:8088 INFO: Shutting down ← 自动关闭了 INFO: Finished server process
2. 创建 systemd 服务(关键!)
我创建了一个 systemd 服务来让 CoPaw 稳定运行:
# 创建服务配置文件 cat > /tmp/copaw.service << 'EOF' [Unit] Description=CoPaw AI Assistant After=network.target [Service] Type=simple User=admin WorkingDirectory=/home/admin/.copaw ExecStart=/home/admin/.copaw/venv/bin/python -m uvicorn copaw.app._app:app --host 0.0.0.0 --port 8088 Restart=always RestartSec=5 [Install] WantedBy=multi-user.target EOF # 安装并启动服务 sudo cp /tmp/copaw.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable copaw sudo systemctl start copaw
3. 验证服务运行
# 确认服务状态 sudo systemctl status copaw # 结果:Active: active (running) ✅ # 确认端口监听 netstat -tlnp | grep 8088 # 结果:0.0.0.0:8088 LISTEN ✅
📋 完整操作总结
| 步骤 | 操作 | 目的 |
|---|---|---|
| 1 | 修改 config.json | 监听地址从 127.0.0.1 改为 0.0.0.0 |
| 2 | 创建 systemd 服务 | 让 CoPaw 稳定运行,不自动退出 |
| 3 | 启动 systemd 服务 | sudo systemctl start copaw |
| 4 | 验证端口监听 | 确认 0.0.0.0:8088 正在监听 |
🎯 为什么之前不行?
之前:用
nohup/&后台启动,服务几秒后自动退出现在:用 systemd 管理,服务持续运行,崩溃会自动重启
📌 后续管理命令
# 查看服务状态 sudo systemctl status copaw # 查看实时日志 sudo journalctl -u copaw -f # 重启服务 sudo systemctl restart copaw # 停止服务 sudo systemctl stop copaw # 开机自启(已启用) sudo systemctl enable copaw
现在 CoPaw 已经稳定运行了!访问地址:
http://120.26.253.27:8088
有其他需要帮忙的吗?😊