同時運行多個網關
在單臺機器上以託管服務的形式運行多個配置文件——每個配置文件擁有獨立的機器人令牌(bot tokens)、會話和內存。本頁涵蓋操作層面的注意事項:如何同時啟動所有網關、跨配置文件查看日誌、防止主機進入睡眠狀態,以及從常見的 launchd/systemd 問題中恢復。
如果你只運行一個 Hermes 代理,則無需閱讀本頁——請參閱配置文件瞭解基礎知識。
何時使用此功能
當你有兩個或更多需要同時在線的 Hermes 代理時,適合使用此設置。常見場景包括:
- 一個 Telegram 機器人上的個人助理和另一個機器人上的編碼代理
- 每位家庭成員各一個代理,或每個 Slack 工作區各一個代理
- 同一配置的沙盒環境與生產環境實例
- 研究代理 + 寫作代理 + 由 cron 驅動的機器人——每個都擁有隔離的內存和技能
每個配置文件已經擁有其各自的平臺專屬 LaunchAgent(ai.hermes.gateway-<name>.plist)或 systemd 用戶服務(hermes-gateway-<name>.service)。本指南補充了集體管理這些服務的模式。
快速開始
# Create profiles (once)
hermes profile create coder
hermes profile create personal-bot
hermes profile create research
# Configure each
coder setup
personal-bot setup
research setup
# Install each gateway as a managed service
coder gateway install
personal-bot gateway install
research gateway install
# Start them all
coder gateway start
personal-bot gateway start
research gateway start
就是這樣——三個獨立的代理,各自運行在獨立的進程中,在崩潰時和用戶登錄時自動重啟。
一次性啟動、停止或重啟所有網關
CLI 提供了針對單個配置文件的生命週期命令。要對所有配置文件執行操作,可以將它們包裹在一個 shell 循環中。將以下代碼片段放入 ~/.local/bin/hermes-gateways 並執行 chmod +x:
#!/bin/sh
set -eu
# Add or remove profile names here as you create / delete profiles.
profiles="default coder personal-bot research"
usage() {
echo "Usage: hermes-gateways {start|stop|restart|status|list}"
}
run_for_profile() {
profile="$1"
action="$2"
if [ "$profile" = "default" ]; then
hermes gateway "$action"
else
hermes -p "$profile" gateway "$action"
fi
}
action="${1:-}"
case "$action" in
start|stop|restart|status)
for profile in $profiles; do
echo "==> $action $profile"
run_for_profile "$profile" "$action"
done
;;
list)
hermes gateway list
;;
*)
usage
exit 2
;;
esac
然後:
hermes-gateways start # start every configured profile
hermes-gateways stop # stop every configured profile
hermes-gateways restart # restart all
hermes-gateways status # status across all
hermes-gateways list # delegates to `hermes gateway list`
default 配置文件通過 hermes gateway <action>(不帶 -p)進行定位,而不是 hermes -p default gateway <action>。上述包裝腳本同時處理這兩種形式。
管理單個配置文件
每個配置文件安裝的快捷命令:
coder gateway run # foreground (Ctrl-C to stop)
coder gateway start # start the managed service
coder gateway stop # stop the managed service
coder gateway restart # restart
coder gateway status # status
coder gateway install # create the LaunchAgent / systemd unit
coder gateway uninstall # remove the service file
這些命令等同於 hermes -p coder gateway <action>——當配置文件別名不在 PATH 中,或者你需要從腳本中動態定位配置文件時非常有用。
服務文件
每個配置文件都會安裝具有唯一名稱的服務,因此安裝不會發生衝突:
| 平臺 | 路徑 |
|---|---|
| macOS | ~/Library/LaunchAgents/ai.hermes.gateway-<profile>.plist |
| Linux | ~/.config/systemd/user/hermes-gateway-<profile>.service |
默認配置文件保留歷史名稱:ai.hermes.gateway.plist / hermes-gateway.service。
查看日誌
每個配置文件寫入各自的日誌文件:
# Default profile
tail -f ~/.hermes/logs/gateway.log
tail -f ~/.hermes/logs/gateway.error.log
# Named profile
tail -f ~/.hermes/profiles/<name>/logs/gateway.log
tail -f ~/.hermes/profiles/<name>/logs/gateway.error.log
同時流式傳輸所有配置文件的日誌:
tail -f ~/.hermes/logs/gateway.log ~/.hermes/profiles/*/logs/gateway.log
CLI 還提供了一個結構化日誌查看器:
hermes logs -f # follow default profile
hermes -p coder logs -f # follow one profile
hermes logs --help # filters, levels, JSON output
識別實際運行的進程
hermes profile list # profiles + model + gateway state
hermes-gateways status # full status across every profile
launchctl list | grep hermes # macOS — PIDs and labels
systemctl --user list-units 'hermes-gateway-*' # Linux — units
編輯配置
每個配置文件將其配置保存在自己的目錄中:
~/.hermes/profiles/<name>/
├── .env # API keys, bot tokens (chmod 600)
├── config.yaml # model, provider, toolsets, gateway settings
└── SOUL.md # personality / system prompt
默認配置文件直接使用 ~/.hermes/ 目錄,包含相同的三個文件。
使用任意編輯器或通過 CLI 進行編輯:
hermes config set model.model anthropic/claude-sonnet-4 # default profile
coder config set model.model openai/gpt-5 # named profile
編輯 .env 或 config.yaml 後,重啟受影響的網關:
coder gateway restart
# or, for everything:
hermes-gateways restart
保持主機喚醒
網關進程可以全天運行,但操作系統在空閒時仍會嘗試進入睡眠狀態。有兩種模式:
macOS — caffeinate
caffeinate 內置於 macOS 中,在其運行期間防止系統睡眠。無需安裝。
caffeinate -dis # block display, idle, and system sleep
caffeinate -dis -t 28800 # same, auto-exit after 8 hours
caffeinate -i -w $(cat ~/.hermes/gateway.pid) & # awake while default gateway runs
# Persistent: run in background and forget
nohup caffeinate -dis >/dev/null 2>&1 &
disown
# Inspect / stop
pmset -g assertions | grep -iE 'caffeinate|prevent|user is active'
pkill caffeinate
| 標誌 | 效果 |
|---|---|
-d | 阻止顯示器睡眠 |
-i | 阻止空閒系統睡眠(默認) |
-m | 阻止磁盤睡眠 |
-s | 阻止系統睡眠(僅適用於連接電源的 Mac) |
-u | 模擬用戶活動(防止屏幕鎖定) |
-t N | 在 N 秒後自動退出 |
-w P | 當 PID P 退出時退出 |
caffeinate 無法覆蓋 MacBook 上由硬件控制的合蓋睡眠。如需在合蓋狀態下運行,請更改“節能”/“電池”偏好設置,或使用第三方工具。
Linux — systemd-inhibit 或 loginctl
# Inhibit suspend while a command runs
systemd-inhibit --what=idle:sleep --who=hermes --why="gateways running" \
sleep infinity &
# Allow user services to keep running after logout (recommended)
sudo loginctl enable-linger "$USER"
啟用 lingering(持久化)後,你的 systemd 用戶單元(包括 hermes-gateway-<profile>.service)將在 SSH 斷開連接和重啟後繼續運行。
令牌衝突安全
每個配置文件必須為每個平臺使用唯一的機器人令牌。如果兩個配置文件共享 Telegram、Discord、Slack、WhatsApp 或 Signal 令牌,第二個網關將拒絕啟動,並報出指明衝突配置文件的錯誤。
要審計令牌:
grep -H 'TELEGRAM_BOT_TOKEN\|DISCORD_BOT_TOKEN' \
~/.hermes/.env ~/.hermes/profiles/*/.env
更新代碼
hermes update 拉取最新代碼一次,並將新的捆綁技能同步到每個配置文件中:
hermes update
hermes-gateways restart
用戶修改過的技能永遠不會被覆蓋。
故障排除
"Could not find service in domain for user gui: 501"
你在之前執行過 hermes gateway stop 之後,又運行了 hermes gateway start。CLI 的 stop 命令會執行完整的 launchctl unload,這會將服務從 launchd 的註冊表中移除。CLI 在 start 時會捕獲此特定錯誤,並自動重新加載 plist 文件(↻ launchd job was unloaded; reloading service definition)。服務將正常啟動。無需修復。
崩潰後殘留的 PID
如果某個配置文件的網關顯示為 not running,但進程仍然存活:
ps -ef | grep "hermes_cli.*-p <profile>"
cat ~/.hermes/profiles/<profile>/gateway.pid
kill -TERM <pid> # graceful
kill -KILL <pid> # if that fails after a few seconds
<profile> gateway start
強制對單個服務進行硬重置
# macOS
launchctl unload ~/Library/LaunchAgents/ai.hermes.gateway-<profile>.plist
launchctl load ~/Library/LaunchAgents/ai.hermes.gateway-<profile>.plist
# Linux
systemctl --user restart hermes-gateway-<profile>.service
健康檢查
hermes doctor # default profile
hermes -p <profile> doctor # one profile