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();