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:
@@ -551,17 +551,12 @@ class ClawClient {
|
|||||||
writeFileSync(configFile, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
|
writeFileSync(configFile, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
|
||||||
log.info('clawd', `openclaw config 已更新: ${newOrigin}`);
|
log.info('clawd', `openclaw config 已更新: ${newOrigin}`);
|
||||||
|
|
||||||
// 默认不再 pkill gateway(观察是否会自行重载);恢复旧行为:CLAWD_OPENCLAW_GATEWAY_PKILL=1
|
|
||||||
if (process.env.CLAWD_OPENCLAW_GATEWAY_PKILL === '1') {
|
|
||||||
try {
|
try {
|
||||||
execSync('pkill -9 -x openclaw-gateway', { timeout: 3000 });
|
execSync('pkill -9 -x openclaw-gateway', { timeout: 3000 });
|
||||||
log.info('clawd', 'openclaw-gateway 已终止,等待自动重启');
|
log.info('clawd', 'openclaw-gateway 已终止,等待自动重启');
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
log.info('clawd', 'openclaw-gateway 进程不存在,无需终止');
|
log.info('clawd', 'openclaw-gateway 进程不存在,无需终止');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.info('clawd', '已跳过 openclaw-gateway pkill(需旧行为请设 CLAWD_OPENCLAW_GATEWAY_PKILL=1)');
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.warn('clawd', `openclaw config 更新失败: ${e.message}`);
|
log.warn('clawd', `openclaw config 更新失败: ${e.message}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
|
const { execSync } = require('child_process');
|
||||||
const log = require('./logger');
|
const log = require('./logger');
|
||||||
const { resolveOpenclawConfigFile } = require('./frpc');
|
const { resolveOpenclawConfigFile } = require('./frpc');
|
||||||
|
|
||||||
@@ -13,6 +14,19 @@ const FETCH_TIMEOUT_MS = 10_000;
|
|||||||
/** 拉模型 + 写盘单次飞行:进行中则忽略新的 apply/remove */
|
/** 拉模型 + 写盘单次飞行:进行中则忽略新的 apply/remove */
|
||||||
let _busy = false;
|
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) {
|
function authProfilesPathFromConfig(configFile) {
|
||||||
return path.join(path.dirname(configFile), 'agents', 'main', 'agent', 'auth-profiles.json');
|
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}`);
|
log.info('openclaw-provider', `provider 已移除: ${providerId}`);
|
||||||
|
restartGateway();
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeProviderFromConfig(config, providerId) {
|
function removeProviderFromConfig(config, providerId) {
|
||||||
@@ -267,6 +282,7 @@ function applyFullProviderFromVps(provider, onDone) {
|
|||||||
log.warn('openclaw-provider', `拉模型失败,使用空列表: ${err.message}`);
|
log.warn('openclaw-provider', `拉模型失败,使用空列表: ${err.message}`);
|
||||||
}
|
}
|
||||||
addProviderSync(configFile, name, baseUrl, apiKey, list, defaultModel);
|
addProviderSync(configFile, name, baseUrl, apiKey, list, defaultModel);
|
||||||
|
restartGateway();
|
||||||
if (typeof onDone === 'function') {
|
if (typeof onDone === 'function') {
|
||||||
try {
|
try {
|
||||||
onDone();
|
onDone();
|
||||||
|
|||||||
Reference in New Issue
Block a user