wip(est-test): 개발 중 저장 3 — 깃 싱크(11-08)

This commit is contained in:
2026-11-08 17:44:13 +09:00
parent d39eece45e
commit db71cdbf7c
28 changed files with 1027 additions and 202 deletions
+45 -31
View File
@@ -1,43 +1,57 @@
// 독립 EST 테스트 서버 감시/감독 프로세스
// EST 서버 감시: 작업 데이터 디렉터리는 감시하지 않는다.
const { spawn } = require("node:child_process");
const fs = require("node:fs");
const path = require("node:path");
const base = __dirname;
const serverScript = path.join(base, "server.cjs");
let child,
timer,
restarting = false,
stopping = false;
// data 디렉터리, 로그 파일 등은 제외하고 소스코드 파일만 명시적으로 감시 대상에 포함
const watchArgs = fs
.readdirSync(base)
.filter(
(file) =>
(file.endsWith(".js") ||
file.endsWith(".cjs") ||
file === "index.html" ||
file === "native.css") &&
!file.startsWith(".") &&
file !== "watch-server.cjs",
)
.map((file) => `--watch-path=${path.join(base, file)}`);
function start() {
child = spawn(process.execPath, [path.join(base, "server.cjs")], {
cwd: base,
env: process.env,
stdio: "inherit",
});
child.on("exit", (code, signal) => {
if (stopping) return;
if (restarting) {
restarting = false;
start();
} else {
console.error(`[supervisor] 서버 종료: ${code ?? signal}`);
process.exit(code || 1);
}
});
}
const args = ["--watch", ...watchArgs, serverScript];
console.log("[supervisor] Starting server with watch paths (excluding data/)...");
const child = spawn(process.execPath, args, {
cwd: base,
env: process.env,
stdio: "inherit",
const watcher = fs.watch(base, (event, filename) => {
const name = filename && filename.toString();
if (!name || name === "watch-server.cjs" || !/\.(?:js|cjs|html|css)$/i.test(name)) return;
clearTimeout(timer);
timer = setTimeout(() => {
if (restarting || stopping) return;
restarting = true;
console.log(`[supervisor] 변경 감지: ${name}`);
child.kill();
}, 300);
});
watcher.on("error", (error) => {
console.error(`[supervisor] 감시 오류: ${error.message}`);
stopping = true;
child.kill();
process.exit(1);
});
child.on("exit", (code, signal) => {
console.log(`[supervisor] Server exited with code ${code}, signal ${signal}`);
process.exit(code || 0);
});
for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) {
process.on(sig, () => {
child.kill(sig);
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
process.on(signal, () => {
stopping = true;
clearTimeout(timer);
watcher.close();
child.kill();
process.exit(0);
});
}
start();