style: исправлены кавычки в коде для единообразия
All checks were successful
Build and Deploy Gateway / build-and-deploy (push) Successful in 19s

Refs: None
This commit is contained in:
2026-05-08 19:41:24 +03:00
parent 0cd898d1c1
commit 3e18b833c6

View File

@@ -17,7 +17,7 @@ const APPLY_HISTORY_LIMIT = 10;
fs.mkdirSync(settings.dataDir, { recursive: true }); fs.mkdirSync(settings.dataDir, { recursive: true });
const SINGBOX_PID_FILE = path.join(settings.dataDir, 'singbox.pid'); const SINGBOX_PID_FILE = path.join(settings.dataDir, "singbox.pid");
let singboxProcess = null; let singboxProcess = null;
let singboxStartedAt = null; let singboxStartedAt = null;
@@ -52,24 +52,34 @@ function parseSingboxLevel(line, fallback) {
// ─── PID helpers ──────────────────────────────────────────────────────────── // ─── PID helpers ────────────────────────────────────────────────────────────
function saveSingboxPid(pid) { function saveSingboxPid(pid) {
try { fs.writeFileSync(SINGBOX_PID_FILE, String(pid), 'utf8'); } catch {} try {
fs.writeFileSync(SINGBOX_PID_FILE, String(pid), "utf8");
} catch {}
} }
function readSingboxPid() { function readSingboxPid() {
try { try {
const pid = parseInt(fs.readFileSync(SINGBOX_PID_FILE, 'utf8').trim(), 10); const pid = parseInt(fs.readFileSync(SINGBOX_PID_FILE, "utf8").trim(), 10);
return Number.isFinite(pid) && pid > 0 ? pid : null; return Number.isFinite(pid) && pid > 0 ? pid : null;
} catch { return null; } } catch {
return null;
}
} }
function removeSingboxPid() { function removeSingboxPid() {
try { fs.unlinkSync(SINGBOX_PID_FILE); } catch {} try {
fs.unlinkSync(SINGBOX_PID_FILE);
} catch {}
} }
function isPidAlive(pid) { function isPidAlive(pid) {
if (!pid) return false; if (!pid) return false;
try { process.kill(pid, 0); return true; } try {
catch { return false; } process.kill(pid, 0);
return true;
} catch {
return false;
}
} }
/** /**
@@ -83,8 +93,14 @@ function attachExistingSingbox(pid) {
let exitCb = null; let exitCb = null;
singboxProcess = { singboxProcess = {
pid, pid,
kill: (sig = 'SIGTERM') => { try { process.kill(pid, sig); } catch {} }, kill: (sig = "SIGTERM") => {
once: (event, cb) => { if (event === 'exit') exitCb = cb; }, try {
process.kill(pid, sig);
} catch {}
},
once: (event, cb) => {
if (event === "exit") exitCb = cb;
},
}; };
// Периодически проверяем, что процесс ещё жив // Периодически проверяем, что процесс ещё жив
@@ -95,13 +111,16 @@ function attachExistingSingbox(pid) {
singboxProcess = null; singboxProcess = null;
singboxStartedAt = null; singboxStartedAt = null;
removeSingboxPid(); removeSingboxPid();
pushLog('warning', `sing-box (pid=${pid}) завершился`); pushLog("warning", `sing-box (pid=${pid}) завершился`);
}
if (exitCb) {
exitCb(null, null);
exitCb = null;
} }
if (exitCb) { exitCb(null, null); exitCb = null; }
} }
}, 2000); }, 2000);
pushLog('info', `sing-box подхвачен при старте (pid=${pid})`); pushLog("info", `sing-box подхвачен при старте (pid=${pid})`);
} }
function captureStream(stream, fallbackLevel) { function captureStream(stream, fallbackLevel) {