@aion0/forge 0.2.22 → 0.2.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/forge-server.mjs +27 -10
- package/package.json +1 -1
package/bin/forge-server.mjs
CHANGED
|
@@ -104,6 +104,8 @@ if (resetTerminal) {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
// ── Kill orphan standalone processes ──
|
|
107
|
+
const protectedPids = new Set();
|
|
108
|
+
|
|
107
109
|
function cleanupOrphans() {
|
|
108
110
|
try {
|
|
109
111
|
const out = execSync("ps aux | grep -E 'telegram-standalone|terminal-standalone|next-server|next start|next dev' | grep -v grep | awk '{print $2}'", {
|
|
@@ -112,14 +114,17 @@ function cleanupOrphans() {
|
|
|
112
114
|
if (out) {
|
|
113
115
|
const myPid = String(process.pid);
|
|
114
116
|
for (const pid of out.split('\n').filter(Boolean)) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
const p = pid.trim();
|
|
118
|
+
if (p === myPid) continue;
|
|
119
|
+
if (protectedPids.has(p)) continue; // don't kill processes we just started
|
|
120
|
+
try { process.kill(parseInt(p), 'SIGTERM'); } catch {}
|
|
117
121
|
}
|
|
118
|
-
// Force kill any remaining
|
|
119
122
|
setTimeout(() => {
|
|
120
123
|
for (const pid of out.split('\n').filter(Boolean)) {
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
const p = pid.trim();
|
|
125
|
+
if (p === myPid) continue;
|
|
126
|
+
if (protectedPids.has(p)) continue;
|
|
127
|
+
try { process.kill(parseInt(p), 'SIGKILL'); } catch {}
|
|
123
128
|
}
|
|
124
129
|
}, 2000);
|
|
125
130
|
console.log('[forge] Cleaned up orphan processes');
|
|
@@ -187,17 +192,19 @@ function startBackground() {
|
|
|
187
192
|
}
|
|
188
193
|
|
|
189
194
|
const logFd = openSync(LOG_FILE, 'a');
|
|
190
|
-
const
|
|
195
|
+
const nextBin = join(ROOT, 'node_modules', '.bin', 'next');
|
|
196
|
+
const child = spawn(nextBin, ['start', '-p', String(webPort)], {
|
|
191
197
|
cwd: ROOT,
|
|
192
198
|
stdio: ['ignore', logFd, logFd],
|
|
193
|
-
env: { ...process.env },
|
|
199
|
+
env: { ...process.env, FORGE_EXTERNAL_SERVICES: '1' },
|
|
194
200
|
detached: true,
|
|
195
201
|
});
|
|
196
202
|
|
|
197
203
|
writeFileSync(PID_FILE, String(child.pid));
|
|
204
|
+
protectedPids.add(String(child.pid));
|
|
198
205
|
child.unref();
|
|
199
206
|
|
|
200
|
-
// Start services in background too
|
|
207
|
+
// Start services in background too (cleanupOrphans will skip protectedPids)
|
|
201
208
|
startServices();
|
|
202
209
|
|
|
203
210
|
console.log(`[forge] Started in background (pid ${child.pid})`);
|
|
@@ -217,8 +224,18 @@ if (isStop) {
|
|
|
217
224
|
// ── Restart ──
|
|
218
225
|
if (isRestart) {
|
|
219
226
|
stopServer();
|
|
220
|
-
//
|
|
221
|
-
|
|
227
|
+
// Wait for port to fully release
|
|
228
|
+
const net = await import('node:net');
|
|
229
|
+
for (let i = 0; i < 20; i++) {
|
|
230
|
+
await new Promise(r => setTimeout(r, 500));
|
|
231
|
+
const free = await new Promise(resolve => {
|
|
232
|
+
const s = net.createServer();
|
|
233
|
+
s.once('error', () => resolve(false));
|
|
234
|
+
s.once('listening', () => { s.close(); resolve(true); });
|
|
235
|
+
s.listen(webPort);
|
|
236
|
+
});
|
|
237
|
+
if (free) break;
|
|
238
|
+
}
|
|
222
239
|
startBackground();
|
|
223
240
|
process.exit(0);
|
|
224
241
|
}
|
package/package.json
CHANGED