feat(openclaw): persist config as ~/.openclaw/openclaw.json
- Read gateway token/port via JSON.parse (same structure as former YAML) - Update claw.cutos.ai origin by replacing URLs in JSON string fields - Export resolveOpenclawConfigFile() for frpc + client - Drop js-yaml dependency - install: ExecStartPre touches openvfd only if nodes exist (3528-friendly) - Add tools/deploy-rsync.sh for syncing /opt/clawd over SSH Made-with: Cursor
This commit is contained in:
@@ -6,7 +6,7 @@ const config = require('./config');
|
||||
const log = require('./logger');
|
||||
const { getBoxId } = require('./fingerprint');
|
||||
const { collect } = require('./metrics');
|
||||
const { getDashboardInfo, startTtyd, FrpcManager } = require('./frpc'); // getDashboardInfo 也用于心跳中定期刷新
|
||||
const { getDashboardInfo, resolveOpenclawConfigFile, startTtyd, FrpcManager } = require('./frpc'); // getDashboardInfo 也用于心跳中定期刷新
|
||||
const { ProvisionManager } = require('./provisioning');
|
||||
const { BtMonitor } = require('./bt-monitor');
|
||||
const { hasInternet, getLocalIps } = require('./network');
|
||||
@@ -407,30 +407,65 @@ class ClawClient {
|
||||
// ── OpenClaw 配置 ────────────────────────────────────────────────────────────
|
||||
|
||||
_updateOpenClawOrigin(targetId) {
|
||||
const { existsSync, readFileSync, writeFileSync } = require('fs');
|
||||
const configFile = '/home/sts/.openclaw/config/config.yaml';
|
||||
const { readFileSync, writeFileSync } = require('fs');
|
||||
const configFile = resolveOpenclawConfigFile();
|
||||
|
||||
if (!existsSync(configFile)) {
|
||||
log.warn('clawd', `openclaw 配置文件不存在: ${configFile}`);
|
||||
if (!configFile) {
|
||||
log.warn('clawd', 'openclaw 配置文件不存在(~/.openclaw/openclaw.json 等候选路径均未找到)');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const content = readFileSync(configFile, 'utf8');
|
||||
const raw = readFileSync(configFile, 'utf8');
|
||||
const config = JSON.parse(raw);
|
||||
const newOrigin = `https://${targetId}.claw.cutos.ai`;
|
||||
const re = /https:\/\/[^"'\s]+\.claw\.cutos\.ai/g;
|
||||
|
||||
// 替换 https://任意子域.claw.cutos.ai 为目标域名
|
||||
const updated = content.replace(
|
||||
/https:\/\/[^"'\s]+\.claw\.cutos\.ai/g,
|
||||
newOrigin
|
||||
);
|
||||
/** 与原 YAML 全文替换等价:遍历 JSON 内所有字符串并替换匹配的 origin */
|
||||
const replaceOriginStrings = (node) => {
|
||||
let changed = false;
|
||||
if (typeof node === 'string') {
|
||||
return false;
|
||||
}
|
||||
if (Array.isArray(node)) {
|
||||
for (let i = 0; i < node.length; i++) {
|
||||
const v = node[i];
|
||||
if (typeof v === 'string') {
|
||||
const next = v.replace(re, newOrigin);
|
||||
if (next !== v) {
|
||||
node[i] = next;
|
||||
changed = true;
|
||||
}
|
||||
} else if (v && typeof v === 'object') {
|
||||
changed = replaceOriginStrings(v) || changed;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
if (node && typeof node === 'object') {
|
||||
for (const k of Object.keys(node)) {
|
||||
const v = node[k];
|
||||
if (typeof v === 'string') {
|
||||
const next = v.replace(re, newOrigin);
|
||||
if (next !== v) {
|
||||
node[k] = next;
|
||||
changed = true;
|
||||
}
|
||||
} else if (v && typeof v === 'object') {
|
||||
changed = replaceOriginStrings(v) || changed;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if (updated === content) {
|
||||
if (!replaceOriginStrings(config)) {
|
||||
log.info('clawd', `openclaw origin 已是 ${newOrigin},无需变更`);
|
||||
return;
|
||||
}
|
||||
|
||||
writeFileSync(configFile, updated, 'utf8');
|
||||
writeFileSync(configFile, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
|
||||
log.info('clawd', `openclaw config 已更新: ${newOrigin}`);
|
||||
|
||||
// 文件有变化,kill -9 openclaw-gateway,让它被 systemd --user 自动拉起
|
||||
|
||||
Reference in New Issue
Block a user