Skip to content

Commit 3b36dd3

Browse files
committed
1 parent 6a6b430 commit 3b36dd3

3 files changed

Lines changed: 37 additions & 32 deletions

File tree

bun.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"ws": "^8.19.0"
7272
},
7373
"devDependencies": {
74-
"@types/bun": "^1.3.9",
74+
"@types/bun": "^1.3.14",
7575
"@types/pidusage": "^2.0.5",
7676
"@types/ws": "^8.18.1",
7777
"bun-types": "latest",

src/process-manager.ts

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -357,35 +357,38 @@ import type { ReadableStreamController } from "bun";
357357
await Bun.write(DUMP_FILE, JSON.stringify(data, null, 2));
358358
}
359359

360-
async resurrect(): Promise<ProcessState[]> {
361-
try {
362-
const file = Bun.file(DUMP_FILE);
363-
if (!(await file.exists())) return [];
364-
const data = await file.json();
365-
const states: ProcessState[] = [];
366-
367-
for (const item of data) {
368-
const result = await this.start({
369-
name: item.config.name,
370-
script: item.config.script,
371-
args: item.config.args,
372-
cwd: item.config.cwd,
373-
env: item.config.env,
374-
autorestart: item.config.autorestart,
375-
maxRestarts: item.config.maxRestarts,
376-
watch: item.config.watch,
377-
instances: 1,
378-
execMode: item.config.execMode,
379-
port: item.config.port,
380-
healthCheckUrl: item.config.healthCheckUrl,
381-
});
382-
states.push(...result);
383-
}
384-
return states;
385-
} catch {
386-
return [];
387-
}
388-
}
360+
// src/process-manager.ts
361+
362+
async resurrect(): Promise<ProcessState[]> {
363+
try {
364+
const file = Bun.file(DUMP_FILE);
365+
if (!(await file.exists())) return [];
366+
const data = await file.json();
367+
const states: ProcessState[] = [];
368+
369+
for (const item of data) {
370+
371+
// Pass the FULL saved config to restore all options (interpreter, logs, cron, etc.)
372+
const result = await this.start(item.config);
373+
374+
// Restore the restart counts for continuity and observability
375+
for (const proc of result) {
376+
const container = this.processes.get(proc.pm_id);
377+
if (container) {
378+
container.restartCount = item.restartCount ?? 0;
379+
container.unstableRestarts = item.unstableRestarts ?? 0;
380+
}
381+
}
382+
states.push(...result);
383+
}
384+
385+
return states;
386+
387+
} catch (err) {
388+
console.error("[bm2] Resurrect failed:", err);
389+
return [];
390+
}
391+
}
389392

390393
async startEcosystem(config: EcosystemConfig): Promise<ProcessState[]> {
391394
const states: ProcessState[] = [];

0 commit comments

Comments
 (0)