fix: restartGateway 改异步,修复 inactive 时 PIN 不闪问题

原来 removeProviderByName 内用 execSync 调 pkill,在 showPin 前
阻塞事件循环约 100ms+;若 vfdservice 是 gateway 子进程则管道无
读端,导致 showPin 写入失败或 blink setTimeout 无法触发。

改为 exec(异步):pkill 在后台执行,不阻塞事件循环,LED/VFD
操作(showPin blink)可正常调度。

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-04-03 11:41:59 +08:00
parent 7c9a6e913e
commit f4efb13612

View File

@@ -4,7 +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 { exec } = require('child_process');
const log = require('./logger'); const log = require('./logger');
const { resolveOpenclawConfigFile } = require('./frpc'); const { resolveOpenclawConfigFile } = require('./frpc');
@@ -17,14 +17,18 @@ let _busy = false;
/** /**
* 终止 openclaw-gateway 进程,由 systemd --user 自动重新拉起以读取新配置。 * 终止 openclaw-gateway 进程,由 systemd --user 自动重新拉起以读取新配置。
* 每次写盘 openclaw.json 成功后应调用一次。 * 每次写盘 openclaw.json 成功后应调用一次。
* 使用异步 exec不阻塞 Node.js 事件循环,避免干扰 LED / VFD 等后续操作。
*/ */
function restartGateway() { function restartGateway() {
try { exec('pkill -9 -x openclaw-gateway', (err) => {
execSync('pkill -9 -x openclaw-gateway', { timeout: 3000 }); if (err && err.code !== 1) {
log.warn('openclaw-provider', `restartGateway: ${err.message}`);
} else if (!err) {
log.info('openclaw-provider', 'openclaw-gateway 已终止,等待自动重启'); log.info('openclaw-provider', 'openclaw-gateway 已终止,等待自动重启');
} catch (_) { } else {
log.info('openclaw-provider', 'openclaw-gateway 进程不存在,无需终止'); log.info('openclaw-provider', 'openclaw-gateway 进程不存在,无需终止');
} }
});
} }
function authProfilesPathFromConfig(configFile) { function authProfilesPathFromConfig(configFile) {