@@ -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