From 701251f19b3e429a7b20303a5a09b734e5a77296 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Fri, 3 Apr 2026 10:50:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=86=99=E7=9B=98=20openclaw.json=20?= =?UTF-8?q?=E5=90=8E=E8=87=AA=E5=8A=A8=E9=87=8D=E5=90=AF=20gateway?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - openclaw-provider.js: 新增 restartGateway(),在 removeProviderByName 和 applyFullProviderFromVps 写盘成功后均调用,确保 inactive/active 两路都能触发重启 - client.js: _updateOpenClawOrigin 去掉 CLAWD_OPENCLAW_GATEWAY_PKILL env var 门控,origin 变更后默认重启 Made-with: Cursor --- lib/client.js | 15 +++++---------- lib/openclaw-provider.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/client.js b/lib/client.js index 17c25a4..abee816 100644 --- a/lib/client.js +++ b/lib/client.js @@ -551,16 +551,11 @@ 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)'); + try { + execSync('pkill -9 -x openclaw-gateway', { timeout: 3000 }); + log.info('clawd', 'openclaw-gateway 已终止,等待自动重启'); + } catch (_) { + log.info('clawd', 'openclaw-gateway 进程不存在,无需终止'); } } catch (e) { log.warn('clawd', `openclaw config 更新失败: ${e.message}`); diff --git a/lib/openclaw-provider.js b/lib/openclaw-provider.js index beb6414..ed2a0f0 100644 --- a/lib/openclaw-provider.js +++ b/lib/openclaw-provider.js @@ -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();