【踩坑系列3】飞书机器人集体“失联“?3 个 Gateway 进程让我差点崩溃!一个测试老兵的排查实录

20 阅读11分钟

 配置好的 3 个飞书机器人突然全部不回复了!检查配置一切正常,凭证也没问题,但就是没反应!本文记录我从发现问题到彻底解决的完整过程,包含 systemd 服务配置的最佳实践和血泪教训。建议收藏!

开篇:三个机器人集体"哑火"了

事情是这样的。

我在飞书上配置了三个机器人应用,分别是:

  1. 飞书机器人 (主) - 用于测试小分队群
  1. 飞书机器人 2 - 用于个人测试
  1. 飞书机器人 3 - 用于日常使用

之前用得好好的,每天自动推送 Morning AI 资讯,回复消息也正常。

突然有一天早上 ,我发现:

发消息完全不回复了!三个机器人,集体"失联"!

第一步:检查配置,一切正常

我首先检查了配置文件。

打开 ~/.hermes/config.yaml

platforms:
  feishu:
    enabled: true
    extra:
      app_id: <你的飞书应用 ID>
      app_secret: <你的飞书应用密钥>
      token: <你的飞书应用 Token>
  feishu_2:
    enabled: true
    extra:
      app_id: <你的飞书应用 ID 2>
      app_secret: <你的飞书应用密钥 2>
      token: <你的飞书应用 Token 2>
  feishu_3:
    enabled: true
    extra:
      app_id: <你的飞书应用 ID 3>
      app_secret: <你的飞书应用密钥 3>
      token: <你的飞书应用 Token 3>

配置没问题

三个应用都启用了,凭证也都在。

我又检查了 .env

~/.hermes-feishu/.env
FEISHU_APP_ID=<你的飞书应用 ID>
FEISHU_APP_SECRET=<你的飞书应用密钥>
FEISHU_DOMAIN=feishu

# ~/.hermes-feishu2/.env
FEISHU_APP_ID=<你的飞书应用 ID 2>
FEISHU_APP_SECRET=<你的飞书应用密钥 2>
FEISHU_DOMAIN=feishu

# ~/.hermes-feishu3/.env
FEISHU_APP_ID=<你的飞书应用 ID 3>
FEISHU_APP_SECRET=<你的飞书应用密钥 3>
FEISHU_DOMAIN=feishu

也没问题!

---

第二步:深入排查,发现真相

既然配置没问题,那问题出在哪?

我决定检查 Gateway 进程。

# 查看所有 gateway 进程
ps aux | grep "hermes_cli.main gateway" | grep -v grep

输出结果:

zhou  23954  0.4  3.6  ...  hermes_cli.main gateway  (HERMES_HOME=/home/zhou/.hermes-A)
zhou  23956  0.1  2.1  ...  hermes_cli.main gateway  (HERMES_HOME=/home/zhou/.hermes-B)
zhou  23957  0.2  1.3  ...  hermes_cli.main gateway  (HERMES_HOME=/home/zhou/.hermes-C)
zhou  23958  0.3  2.6  ...  hermes_cli.main gateway  (HERMES_HOME=/home/zhou/.hermes-D)
zhou  55913  1.8  2.7  ...  hermes_cli.main gateway  (HERMES_HOME=/home/zhou/.hermes-E)

5 个 Gateway 进程,但没有一个是飞书相关的!

Python 脚本验证:

import subprocess
import os

result = subprocess.run(['ps', 'aux'], capture_output=True, text=True)

gateway_processes = []
for line in result.stdout.split('\n'):
    if 'hermes_cli.main gateway' in line and 'grep' not in line:
        parts = line.split()
        if len(parts) > 2:
            pid = parts[1]
            gateway_processes.append(pid)

print(f"找到 {len(gateway_processes)} 个 Gateway 进程")

for pid in gateway_processes:
    environ_path = f"/proc/{pid}/environ"
    if os.path.exists(environ_path):
        with open(environ_path, 'r') as f:
            environ = f.read().replace('\0', '\n')
            for line in environ.split('\n'):
                if 'HERMES_HOME' in line:
                    print(f"  PID {pid}: {line}")

输出:

找到 5 个 Gateway 进程
  PID 23954: HERMES_HOME=/home/zhou/.hermes-A
  PID 23956: HERMES_HOME=/home/zhou/.hermes-B
  PID 23957: HERMES_HOME=/home/zhou/.hermes-C
  PID 23958: HERMES_HOME=/home/zhou/.hermes-D
  PID 55913: HERMES_HOME=/home/zhou/.hermes-E

一个飞书的都没有!

真相大白:Gateway 进程根本没启动

Hermes 的 Gateway 进程负责:

  1. 接收飞书的消息
  1. 调用 AI 处理
  1. 发送回复

没有 Gateway = 机器人离线 = 不会回复

我之前只配置了应用,但忘记启动 Gateway 进程了!

更准确地说,我之前可能是手动启动过,但服务器重启后,Gateway 进程就没了。

这就是典型的"配置了但没完全配置"!

这种问题,必须用 systemd 一劳永逸!

---

终极解决方案:systemd 服务配置

既然手动启动不可靠,那就用 systemd 管理!

方案对比

方案优点缺点推荐度
手动启动简单直接重启后失效⭐⭐
后台脚本稍微持久不够规范⭐⭐⭐
systemd 服务开机自启、自动重启、日志管理需要学习成本⭐⭐⭐⭐⭐

步骤 1:创建 systemd 服务文件

为每个飞书应用创建服务文件:

mkdir -p ~/.config/systemd/user

服务文件 :~/.config/systemd/user/hermes-gateway@feishu.service

[Unit]
Description=Hermes Gateway - 飞书机器人 (主)
After=network.target

[Service]
Type=simple
Environment=HERMES_HOME=/home/zhou/.hermes-feishu
WorkingDirectory=/home/zhou/hermes-agent
ExecStart=/home/zhou/hermes-agent/venv/bin/python -m hermes_cli.main gateway run
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=hermes-feishu

# 资源限制
LimitNOFILE=65536
Nice=10

[Install]
WantedBy=default.target

步骤 2:启用并启动服务

# 重载 systemd 配置
systemctl --user daemon-reload

# 启用服务(开机自启)
systemctl --user enable hermes-gateway@feishu.service
systemctl --user enable hermes-gateway@feishu2.service
systemctl --user enable hermes-gateway@feishu3.service

# 启动服务
systemctl --user start hermes-gateway@feishu.service
systemctl --user start hermes-gateway@feishu2.service
systemctl --user start hermes-gateway@feishu3.service

步骤 3:验证服务状态

# 查看服务状态
systemctl --user status hermes-gateway@feishu.service
systemctl --user status hermes-gateway@feishu2.service
systemctl --user status hermes-gateway@feishu3.service

# 查看日志
journalctl --user -u hermes-gateway@feishu.service -f

输出示例:

hermes-gateway@feishu.service - Hermes Gateway - 飞书机器人 (主)
     Loaded: loaded (/home/zhou/.config/systemd/user/hermes-gateway@feishu.service; enabled)
     Active: active (running) since Tue 2026-04-15 10:30:00 CST
   Main PID: 89050 (python)
     Status: "Gateway is running"

步骤 4:验证 Gateway 进程

# 检查进程
ps aux | grep "hermes_cli.main gateway" | grep -v grep

# 检查环境变量
cat /proc/89050/environ | tr '\0' '\n' | grep HERMES_HOME

输出:

zhou  89050  2.0  3.1  ...  python -m hermes_cli.main gateway run
  HERMES_HOME=/home/zhou/.hermes-feishu

✅ 成功!

配置前后对比

维度配置前配置后
Gateway 进程❌ 无✅ 3 个运行中
开机自启❌ 否✅ 是
自动重启❌ 否✅ 是(崩溃后自动重启)
日志管理❌ 无✅ journalctl 统一管理
资源限制❌ 无✅ 有限制(防止资源耗尽)

---

血泪教训总结

1. 配置≠运行

❌ 错误认知:配置好了 = 能用了
✅ 正确认知:配置 + 启动 + 持久化 = 真正能用

很多工具都是这样:

  • 配置只是第一步
  • 还需要启动服务
  • 最好配置持久化(systemd)

2. 检查进程是最好的排查手段

排查问题的黄金法则:

# 1. 先看进程在不在
ps aux | grep 进程名

# 2. 再看环境变量对不对
cat /proc/PID/environ | tr '\0' '\n'

# 3. 最后看日志
journalctl -u 服务名 -f

90% 的问题都能通过这三步定位!

剩下的 10%,用第 4 步:重启试试!

3. systemd 是 Linux 服务管理的最佳实践

systemd 的优势:

功能说明
开机自启服务器重启后自动启动
自动重启进程崩溃后自动恢复
日志管理统一通过 journalctl 查看
资源限制防止单个服务耗尽资源
依赖管理可以设置服务启动顺序

强烈建议所有长期运行的服务都用 systemd 管理!

不要像我一样,等到机器人集体失联才想起来!

4. 多实例配置要隔离

我的三个飞书机器人,每个都有独立的:

  • HERMES_HOME 目录
  • .env 配置文件
  • systemd 服务

好处:

  • 互不影响
  • 独立重启
  • 独立日志
  • 独立配置

---

完整命令速查

创建服务文件

mkdir -p ~/.config/systemd/user
nano ~/.config/systemd/user/hermes-gateway@应用名.service

启用服务

# 重载配置
systemctl --user daemon-reload

# 启用(开机自启)
systemctl --user enable hermes-gateway@应用名.service

# 启动
systemctl --user start hermes-gateway@应用名.service

# 停止
systemctl --user stop hermes-gateway@应用名.service

# 重启
systemctl --user restart hermes-gateway@应用名.service

查看状态

# 服务状态
systemctl --user status hermes-gateway@应用名.service

# 查看日志
journalctl --user -u hermes-gateway@应用名.service -f

# 查看最近 100 行
journalctl --user -u hermes-gateway@应用名.service -n 100

检查进程

# 查看进程
ps aux | grep "hermes_cli.main gateway"

# 查看环境变量
cat /proc/PID/environ | tr '\0' '\n' | grep HERMES_HOME

这个问题看似简单,但实际上反映了一个常见的误区:

配置好了 ≠ 能用了

希望这篇文章能帮你避免同样的坑。

附录:完整的服务文件模板

# ~/.config/systemd/user/hermes-gateway@应用名.service

[Unit]
Description=Hermes Gateway - 应用描述
After=network.target

[Service]
Type=simple
Environment=HERMES_HOME=/home/zhou/.hermes-应用名
WorkingDirectory=/home/zhou/hermes-agent
ExecStart=/home/zhou/hermes-agent/venv/bin/python -m hermes_cli.main gateway run
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=hermes-应用名

# 资源限制(可选)
LimitNOFILE=65536
Nice=10

[Install]
WantedBy=default.target

替换 应用名 为你的实际名称即可!

在我解决完这个问题后的第二天,问题复发了。

问题复发主要原因是我重启了一次电脑,结果:三个机器人再次集体失联。

发消息完全不回复,就像第一次遇到问题时一样。我明明已经配置好了,难道又要重新排查一遍?到底是哪里出了问题?

🔍 深入排查

这次我直接检查 systemd 服务状态:

systemctl --user status hermes-gateway@feishu.service


● hermes-gateway@feishu.service - Hermes Gateway - 飞书机器人 (主)
     Loaded: loaded (enabled; preset: enabled)
     Active: activating (auto-restart) (Result: exit-code)
    Process: 29810 ExecStart=/home/zhou/-feishu/hermes-agent/venv/bin/python ...
              (code=exited, status=203/EXEC)

关键信息:

  • 状态:activating (auto-restart) — 服务在反复重启

    错误代码:203/EXEC — 执行文件找不到

    问题路径:/home/zhou/-feishu/hermes-agent/ — 这个路径不存在!

  • 根本原因:systemd 服务文件中的ExecStart路径配置错误!

正确的路径应该是:

ExecStart=/home/zhou/hermes-agent/venv/bin/python -m hermes_cli.main gateway run

但实际配置的是:

ExecStart=/home/zhou/-feishu/hermes-agent/venv/bin/python -m hermes_cli.main gateway run

因为我之前是手动启动的网关进程,用的是正确的路径。但配置 systemd 服务时,不知道什么原因(可能是复制粘贴时的失误),路径写错了。

重启电脑后,systemd 尝试自动启动服务,但找不到执行文件,所以反复重启失败。

✅ 彻底解决方案

步骤 1:检查所有服务文件

# 查看 3 个飞书服务文件
cat ~/.config/systemd/user/hermes-gateway@feishu.service | grep ExecStart
cat ~/.config/systemd/user/hermes-gateway@feishu2.service | grep ExecStart
cat ~/.config/systemd/user/hermes-gateway@feishu3.service | grep ExecStart

输出:

ExecStart=/home/zhou/-feishu/hermes-agent/venv/bin/python -m hermes_cli.main gateway run
ExecStart=/home/zhou/-feishu2/hermes-agent/venv/bin/python -m hermes_cli.main gateway run
ExecStart=/home/zhou/-feishu3/hermes-agent/venv/bin/python -m hermes_cli.main gateway run

三个都有问题!

步骤 2:修复服务文件

# 修复 feishu
sed -i 's|/home/zhou/-feishu/hermes-agent|/home/zhou/hermes-agent|g' \
  ~/.config/systemd/user/hermes-gateway@feishu.service

# 修复 feishu2
sed -i 's|/home/zhou/-feishu2/hermes-agent|/home/zhou/hermes-agent|g' \
  ~/.config/systemd/user/hermes-gateway@feishu2.service

# 修复 feishu3
sed -i 's|/home/zhou/-feishu3/hermes-agent|/home/zhou/hermes-agent|g' \
  ~/.config/systemd/user/hermes-gateway@feishu3.service

步骤 3:验证修复结果

grep ExecStart ~/.config/systemd/user/hermes-gateway@feishu*.service

输出应该是:

ExecStart=/home/zhou/hermes-agent/venv/bin/python -m hermes_cli.main gateway run
ExecStart=/home/zhou/hermes-agent/venv/bin/python -m hermes_cli.main gateway run
ExecStart=/home/zhou/hermes-agent/venv/bin/python -m hermes_cli.main gateway run

步骤 4:重载并重启服务

# 重载 systemd 配置
systemctl --user daemon-reload

# 重启 3 个飞书网关
systemctl --user restart hermes-gateway@feishu.service \
                       hermes-gateway@feishu2.service \
                       hermes-gateway@feishu3.service

# 验证状态
systemctl --user status hermes-gateway@feishu*.service

输出:

● hermes-gateway@feishu.service - Hermes Gateway - 飞书机器人 (主)
     Active: active (running) 

● hermes-gateway@feishu2.service - Hermes Gateway - 飞书机器人 2
     Active: active (running) 

● hermes-gateway@feishu3.service - Hermes Gateway - 飞书机器人 3
     Active: active (running) 

✅ 成功!三个机器人都恢复了!

💡 血泪教训 2.0

这是用复发换来的教训,更加珍贵!

1. 配置路径一定要验证!

# 配置完成后,立即验证路径是否存在
ls -la /home/zhou/hermes-agent/venv/bin/python

# 测试执行
/home/zhou/hermes-agent/venv/bin/python -m hermes_cli.main gateway run --help

不要相信复制粘贴,一定要亲手验证!

2. systemd 服务文件中的路径必须是绝对路径且真实存在

相对路径、错误的路径都会导致 203/EXEC 错误。

3. 重启是检验服务配置的唯一标准

# 配置完成后,一定要重启测试
sudo reboot

# 重启后立即检查服务状态
systemctl --user status hermes-gateway@*.service

🔧 快速排查命令清单

# 1. 检查服务状态
systemctl --user status hermes-gateway@feishu*.service

# 2. 查看错误日志
journalctl --user -u hermes-gateway@feishu.service -n 50 --no-pager

# 3. 检查 ExecStart 路径
grep ExecStart ~/.config/systemd/user/hermes-gateway@*.service

# 4. 验证路径是否存在
cat ~/.config/systemd/user/hermes-gateway@feishu.service | \
  grep ExecStart | \
  awk '{print $2}' | \
  xargs ls -la

# 5. 重载并重启
systemctl --user daemon-reload && \
systemctl --user restart hermes-gateway@feishu*.service

---

最终总结

这个问题经历了两次复发,才找到根本原因:

  1. 第一次 :配置了但没启动 Gateway → 用 systemd 解决
  1. 第二次 :systemd 路径配置错误 → 修正 ExecStart 路径

配置长期运行的服务,一定要:

  1. ✅ 用 systemd 管理
  1. ✅ 验证所有路径真实存在
  1. ✅ 重启测试自动启动
  1. ✅ 定期检查日志

希望这篇文章能帮你一次性配置成功,不要踩我踩过的坑! 😅

---

如果你觉得这篇文章有用,欢迎:

  • 👍点赞 - 让更多测试同行看到
  • 💬评论 - 分享你遇到的类似问题
  • 📢转发 - 帮助更多被 Gateway 折磨的开发者
  • 🔔关注 - 获取更多 Hermes 测试实战干货

你的支持是我持续创作的最大动力!