@@ -446,6 +446,63 @@ export class ProcessManager extends EventEmitter {
446446 return this . runtimeState . getAllDormantProcessNames ( ) ;
447447 }
448448
449+ /**
450+ * Remove a server completely (handles both active and dormant states)
451+ * This is the method to call when a server is being uninstalled
452+ * Returns info about what was removed
453+ */
454+ async removeServerCompletely (
455+ installationName : string ,
456+ timeout : number = 10000
457+ ) : Promise < { active : boolean ; dormant : boolean } > {
458+ this . logger . info ( { operation : 'remove_server_completely_start' ,
459+ installation_name : installationName
460+ } , `Removing server completely: ${ installationName } ` ) ;
461+
462+ const result = { active : false , dormant : false } ;
463+
464+ // Check if active process exists and terminate it
465+ const processInfo = this . getProcessByName ( installationName ) ;
466+ if ( processInfo ) {
467+ this . logger . info ( {
468+ operation : 'remove_server_terminating_active' ,
469+ installation_name : installationName ,
470+ process_id : processInfo . id ,
471+ status : processInfo . status
472+ } , `Terminating active process: ${ installationName } ` ) ;
473+
474+ await this . terminateProcess ( processInfo , timeout ) ;
475+ result . active = true ;
476+ }
477+
478+ // Check if dormant config exists and remove it
479+ if ( this . runtimeState ) {
480+ const dormantConfig = this . runtimeState . getDormantConfig ( installationName ) ;
481+ if ( dormantConfig ) {
482+ this . logger . info ( {
483+ operation : 'remove_server_clearing_dormant' ,
484+ installation_name : installationName ,
485+ team_id : dormantConfig . team_id
486+ } , `Clearing dormant config: ${ installationName } ` ) ;
487+
488+ this . runtimeState . removeDormantConfig ( installationName ) ;
489+ result . dormant = true ;
490+ }
491+ }
492+
493+ // Clean up restart attempts tracking
494+ this . restartAttempts . delete ( installationName ) ;
495+
496+ this . logger . info ( {
497+ operation : 'remove_server_completely_success' ,
498+ installation_name : installationName ,
499+ removed_active : result . active ,
500+ removed_dormant : result . dormant
501+ } , `Server removed completely: ${ installationName } (active: ${ result . active } , dormant: ${ result . dormant } )` ) ;
502+
503+ return result ;
504+ }
505+
449506 /**
450507 * Get or respawn a process if it's dormant
451508 * This method checks active processes first, then dormant configs, and respawns if needed
0 commit comments