diff --git a/lib/client.js b/lib/client.js index 855ecbb..ce2e0f1 100644 --- a/lib/client.js +++ b/lib/client.js @@ -3,7 +3,7 @@ const fs = require('fs'); const { getNotifySocket } = require('./systemd-env'); const WebSocket = require('ws'); -const { execFileSync } = require('child_process'); +const { execFileSync, exec } = require('child_process'); const config = require('./config'); const log = require('./logger'); const { getBoxId } = require('./fingerprint'); @@ -101,6 +101,10 @@ class ClawClient { async start() { log.info('clawd', `启动中... 服务器 = ${this._cfg.server}`); + if (this._cfg.claw_id) { + this._setHostname(this._cfg.claw_id); + } + // 启动时关 alarm;若本地已记为已激活,立即亮 pwr(不等首包 connected) led.status.off(); if (this._cfg.activated) { @@ -416,6 +420,7 @@ class ClawClient { this._cfg.claw_id = msg.claw_id; this._cfg.token = msg.token; config.save(this._cfg); + this._setHostname(msg.claw_id); if (isNew) { log.info('clawd', `注册成功!claw_id = ${msg.claw_id}`); @@ -469,6 +474,19 @@ class ClawClient { } } + // ── Hostname ───────────────────────────────────────────────────────────────── + + _setHostname(clawId) { + const hostname = `claw-${clawId}`; + exec(`sudo hostname ${hostname}`, (err) => { + if (err) { + log.warn('clawd', `设置 hostname 失败: ${err.message}`); + } else { + log.info('clawd', `hostname → ${hostname}`); + } + }); + } + // ── OpenClaw 配置 ──────────────────────────────────────────────────────────── _updateOpenClawOrigin(targetId) {