kill daemon on app shutdown

This commit is contained in:
Christian Weichel 2019-05-08 14:09:53 +02:00
parent 6d1e486518
commit b9f5f251af

View File

@ -1,5 +1,5 @@
import * as os from 'os';
import { exec } from 'child_process';
import { exec, ChildProcess } from 'child_process';
import { join, resolve } from 'path';
import { inject, injectable, named } from 'inversify';
import { ILogger } from '@theia/core/lib/common/logger';
@ -20,6 +20,8 @@ export class ArduinoDaemon implements BackendApplicationContribution {
@inject(ToolOutputServiceServer)
protected readonly toolOutputService: ToolOutputServiceServer;
protected process: ChildProcess | undefined;
protected isReady = new Deferred<boolean>();
async onStart() {
@ -46,6 +48,8 @@ export class ArduinoDaemon implements BackendApplicationContribution {
if (daemon.stderr) {
daemon.on('exit', (code, signal) => DaemonLog.log(this.logger, `Daemon exited with code: ${code}. Signal was: ${signal}.`));
}
this.process = daemon;
await new Promise((resolve, reject) => setTimeout(resolve, 2000));
this.isReady.resolve();
} catch (error) {
@ -53,4 +57,13 @@ export class ArduinoDaemon implements BackendApplicationContribution {
}
}
onStop() {
if (!this.process) {
return;
}
DaemonLog.log(this.logger, `Shutting down daemon.`);
this.process.kill("SIGTERM");
}
}