File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,6 +84,20 @@ export class Daemon extends BaseConfig<DaemonFile> {
8484 }
8585}
8686
87+ export function processRunning ( pid : number ) : boolean {
88+ try {
89+ const r = process . kill ( pid , 0 ) ;
90+
91+ if ( typeof r === 'boolean' ) {
92+ return r ;
93+ }
94+
95+ return true ;
96+ } catch ( e ) {
97+ return e . code === 'EPERM' ;
98+ }
99+ }
100+
87101export async function checkForDaemon ( env : IonicEnvironment ) : Promise < number > {
88102 const config = await env . config . load ( ) ;
89103
@@ -93,9 +107,8 @@ export async function checkForDaemon(env: IonicEnvironment): Promise<number> {
93107
94108 const f = await env . daemon . getPid ( ) ;
95109
96- env . log . debug ( ( ) => `Daemon pid file found (${ chalk . bold ( String ( f ) ) } )` ) ;
97-
98- if ( f ) {
110+ if ( f && processRunning ( f ) ) {
111+ env . log . debug ( ( ) => `Daemon found (pid: ${ chalk . bold ( String ( f ) ) } )` ) ;
99112 return f ;
100113 }
101114
Original file line number Diff line number Diff line change 99 fsUnlink ,
1010 pkgLatestVersion ,
1111 prettyPath ,
12+ processRunning ,
1213} from '@ionic/cli-utils' ;
1314
1415@CommandMetadata ( {
@@ -51,6 +52,9 @@ export class DaemonCommand extends Command {
5152 this . env . log . info ( `Killing existing daemon process ${ chalk . bold ( String ( f ) ) } .` ) ;
5253 await fsUnlink ( this . env . daemon . pidFilePath ) ;
5354 process . kill ( Number ( f ) ) ;
55+ } else if ( ! processRunning ( f ) ) {
56+ this . env . log . info ( `Process ${ chalk . bold ( String ( f ) ) } not found, deleting pid file.` ) ;
57+ await fsUnlink ( this . env . daemon . pidFilePath ) ;
5458 } else if ( d . latestVersions . latest . ionic && semver . gt ( this . env . plugins . ionic . version , d . latestVersions . latest . ionic ) ) {
5559 this . env . log . info ( `Daemon out-of-date--killing ${ chalk . bold ( String ( f ) ) } .` ) ;
5660 await fsUnlink ( this . env . daemon . pidFilePath ) ;
You can’t perform that action at this time.
0 commit comments