Files
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

2.8 KiB

系统服务安装指南

快速安装(推荐)

cd /home/ubuntu/nanocode/weixin-nanobot-bridge

# 1. 安装服务
sudo ./scripts/install-service.sh

# 2. 启动服务
sudo systemctl start weixin-nanobot-bridge

# 3. 检查状态
sudo systemctl status weixin-nanobot-bridge

使用管理脚本

# 查看所有命令
./scripts/manage.sh help

# 常用命令
./scripts/manage.sh start      # 启动服务
./scripts/manage.sh stop       # 停止服务
./scripts/manage.sh restart    # 重启服务
./scripts/manage.sh status     # 查看状态
./scripts/manage.sh logs       # 查看日志
./scripts/manage.sh test       # 测试 API

手动管理

Bridge 服务

# 启动
sudo systemctl start weixin-nanobot-bridge

# 停止
sudo systemctl stop weixin-nanobot-bridge

# 重启
sudo systemctl restart weixin-nanobot-bridge

# 查看状态
sudo systemctl status weixin-nanobot-bridge

# 查看日志
sudo journalctl -u weixin-nanobot-bridge -f

# 开机自启
sudo systemctl enable weixin-nanobot-bridge

# 取消开机自启
sudo systemctl disable weixin-nanobot-bridge

微信适配器服务(可选)

# 安装服务
sudo ./scripts/install-weixin-service.sh

# 注意:微信服务需要先完成一次扫码登录
# 首次运行需要手动执行:
node weixin-bridge.js
# 扫码登录成功后,按 Ctrl+C 退出
# 然后再启动服务:
sudo systemctl start weixin-nanobot-adapter

验证安装

# 1. 检查服务状态
sudo systemctl status weixin-nanobot-bridge

# 2. 检查端口
lsof -i :5000

# 3. 测试 API
./scripts/manage.sh test
# 或
curl http://$(curl -s ifconfig.me):5000/health

故障排查

服务无法启动

# 查看详细错误
sudo journalctl -u weixin-nanobot-bridge -n 50

# 检查日志文件
tail -f logs/server.log
tail -f logs/service-error.log

端口被占用

# 查看占用进程
lsof -i :5000

# 结束占用进程
kill -9 <PID>

# 重启服务
sudo systemctl restart weixin-nanobot-bridge

权限问题

# 检查文件权限
ls -la src/server.py

# 修复权限
sudo chown -R ubuntu:ubuntu /home/ubuntu/nanocode/weixin-nanobot-bridge

卸载服务

sudo ./scripts/manage.sh uninstall
# 或手动执行:
sudo systemctl stop weixin-nanobot-bridge
sudo systemctl disable weixin-nanobot-bridge
sudo rm /etc/systemd/system/weixin-nanobot-bridge.service
sudo systemctl daemon-reload

系统启动顺序

开机后自动启动顺序:

  1. 网络服务启动
  2. nanobot 启动(如果已配置)
  3. weixin-nanobot-bridge 启动
  4. weixin-nanobot-adapter 启动(如果已配置)

监控检查

可以添加定时检查:

# 添加到 crontab
crontab -e

# 添加以下行(每5分钟检查一次)
*/5 * * * * curl -sf http://localhost:5000/health || sudo systemctl restart weixin-nanobot-bridge