feat: 连接 URL 自动拼接设备号并区分连接失败原因
- server.url 作为通道基地址,设备号统一由 device.id 拼接,消除两处配置不一致的可能 - 断线日志区分「网络不通」与「被服务器拒绝(设备未注册/token 错误)」 - 配置文件补充逐项中文注释 - 移除 PID 文件逻辑 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -8,13 +8,11 @@ hospital-agent.exe (PyInstaller 打包后)
|
||||
职责:
|
||||
1. WebSocket 主动连接 B 端管理服务器(注册/心跳/命令)
|
||||
2. 守护主程序(健康探测 + 宕机拉起)
|
||||
3. 写 PID 文件(pid/hospital-agent.pid)
|
||||
|
||||
由 WinSW/NSSM Windows 服务守护本进程。
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
import threading
|
||||
@@ -43,9 +41,6 @@ def run():
|
||||
config = AgentConfig.load()
|
||||
log.info("Agent 启动:deviceId=%s, server=%s", config.device_id, config.server_url)
|
||||
|
||||
# 写 PID 文件
|
||||
_write_pid_file()
|
||||
|
||||
# 组装组件(延迟导入避免环)
|
||||
from agent.dispatcher import CommandDispatcher
|
||||
from agent.process_guard import ProcessGuard
|
||||
@@ -81,15 +76,5 @@ def _shutdown(signum, frame):
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def _write_pid_file():
|
||||
"""写 PID 文件(pid/hospital-agent.pid)。"""
|
||||
try:
|
||||
os.makedirs("pid", exist_ok=True)
|
||||
with open(os.path.join("pid", "hospital-agent.pid"), "w", encoding="utf-8") as f:
|
||||
f.write(str(os.getpid()))
|
||||
except Exception as e:
|
||||
log.warning("PID 文件写入失败:%s", e)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
Reference in New Issue
Block a user