fix: 写盘 openclaw.json 后自动重启 gateway

- openclaw-provider.js: 新增 restartGateway(),在 removeProviderByName
  和 applyFullProviderFromVps 写盘成功后均调用,确保 inactive/active
  两路都能触发重启
- client.js: _updateOpenClawOrigin 去掉 CLAWD_OPENCLAW_GATEWAY_PKILL
  env var 门控,origin 变更后默认重启

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-04-03 10:50:29 +08:00
parent 12aedaaf85
commit 701251f19b
2 changed files with 21 additions and 10 deletions

View File

@@ -551,17 +551,12 @@ class ClawClient {
writeFileSync(configFile, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
log.info('clawd', `openclaw config 已更新: ${newOrigin}`);
// 默认不再 pkill gateway观察是否会自行重载恢复旧行为CLAWD_OPENCLAW_GATEWAY_PKILL=1
if (process.env.CLAWD_OPENCLAW_GATEWAY_PKILL === '1') {
try {
execSync('pkill -9 -x openclaw-gateway', { timeout: 3000 });
log.info('clawd', 'openclaw-gateway 已终止,等待自动重启');
} catch (_) {
log.info('clawd', 'openclaw-gateway 进程不存在,无需终止');
}
} else {
log.info('clawd', '已跳过 openclaw-gateway pkill需旧行为请设 CLAWD_OPENCLAW_GATEWAY_PKILL=1');
}
} catch (e) {
log.warn('clawd', `openclaw config 更新失败: ${e.message}`);
}

View File

@@ -4,6 +4,7 @@ const fs = require('fs');
const path = require('path');
const http = require('http');
const https = require('https');
const { execSync } = require('child_process');
const log = require('./logger');
const { resolveOpenclawConfigFile } = require('./frpc');
@@ -13,6 +14,19 @@ const FETCH_TIMEOUT_MS = 10_000;
/** 拉模型 + 写盘单次飞行:进行中则忽略新的 apply/remove */
let _busy = false;
/**
* 终止 openclaw-gateway 进程,由 systemd --user 自动重新拉起以读取新配置。
* 每次写盘 openclaw.json 成功后应调用一次。
*/
function restartGateway() {
try {
execSync('pkill -9 -x openclaw-gateway', { timeout: 3000 });
log.info('openclaw-provider', 'openclaw-gateway 已终止,等待自动重启');
} catch (_) {
log.info('openclaw-provider', 'openclaw-gateway 进程不存在,无需终止');
}
}
function authProfilesPathFromConfig(configFile) {
return path.join(path.dirname(configFile), 'agents', 'main', 'agent', 'auth-profiles.json');
}
@@ -143,6 +157,7 @@ function removeProviderByName(providerId) {
}
log.info('openclaw-provider', `provider 已移除: ${providerId}`);
restartGateway();
}
function removeProviderFromConfig(config, providerId) {
@@ -267,6 +282,7 @@ function applyFullProviderFromVps(provider, onDone) {
log.warn('openclaw-provider', `拉模型失败,使用空列表: ${err.message}`);
}
addProviderSync(configFile, name, baseUrl, apiKey, list, defaultModel);
restartGateway();
if (typeof onDone === 'function') {
try {
onDone();