mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
[cli-dev-mode] complete shutdown once devServer stops gracefully (#95822)
Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
46c93b16bb
commit
c35ef75dbb
2 changed files with 43 additions and 6 deletions
|
@ -63,8 +63,6 @@ export class BasePathProxyServer {
|
|||
}
|
||||
|
||||
public async start(options: BasePathProxyServerOptions) {
|
||||
this.log.write('starting basepath proxy server');
|
||||
|
||||
const serverOptions = getServerOptions(this.httpConfig);
|
||||
const listenerOptions = getListenerOptions(this.httpConfig);
|
||||
this.server = createServer(serverOptions, listenerOptions);
|
||||
|
@ -101,7 +99,6 @@ export class BasePathProxyServer {
|
|||
return;
|
||||
}
|
||||
|
||||
this.log.write('stopping basepath proxy server');
|
||||
await this.server.stop();
|
||||
this.server = undefined;
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
*/
|
||||
|
||||
import Path from 'path';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
import * as Rx from 'rxjs';
|
||||
import {
|
||||
map,
|
||||
|
@ -17,6 +19,7 @@ import {
|
|||
distinctUntilChanged,
|
||||
switchMap,
|
||||
concatMap,
|
||||
takeUntil,
|
||||
} from 'rxjs/operators';
|
||||
import { CliArgs } from '@kbn/config';
|
||||
import { REPO_ROOT, CiStatsReporter } from '@kbn/dev-utils';
|
||||
|
@ -30,6 +33,16 @@ import { shouldRedirectFromOldBasePath } from './should_redirect_from_old_base_p
|
|||
import { getServerWatchPaths } from './get_server_watch_paths';
|
||||
import { CliDevConfig } from './config';
|
||||
|
||||
// signal that emits undefined once a termination signal has been sent
|
||||
const exitSignal$ = new Rx.ReplaySubject<undefined>(1);
|
||||
Rx.merge(
|
||||
Rx.fromEvent(process as EventEmitter, 'exit'),
|
||||
Rx.fromEvent(process as EventEmitter, 'SIGINT'),
|
||||
Rx.fromEvent(process as EventEmitter, 'SIGTERM')
|
||||
)
|
||||
.pipe(mapTo(undefined), take(1))
|
||||
.subscribe(exitSignal$);
|
||||
|
||||
// timeout where the server is allowed to exit gracefully
|
||||
const GRACEFUL_TIMEOUT = 5000;
|
||||
|
||||
|
@ -218,9 +231,36 @@ export class CliDevMode {
|
|||
this.log.warn('no-base-path', '='.repeat(100));
|
||||
}
|
||||
|
||||
this.subscription.add(this.optimizer.run$.subscribe(this.observer('@kbn/optimizer')));
|
||||
this.subscription.add(this.watcher.run$.subscribe(this.observer('watcher')));
|
||||
this.subscription.add(this.devServer.run$.subscribe(this.observer('dev server')));
|
||||
this.subscription.add(
|
||||
this.optimizer.run$
|
||||
.pipe(
|
||||
// stop the optimizer as soon as we get an exit signal
|
||||
takeUntil(exitSignal$)
|
||||
)
|
||||
.subscribe(this.observer('@kbn/optimizer'))
|
||||
);
|
||||
|
||||
this.subscription.add(
|
||||
this.watcher.run$
|
||||
.pipe(
|
||||
// stop the watcher as soon as we get an exit signal
|
||||
takeUntil(exitSignal$)
|
||||
)
|
||||
.subscribe(this.observer('watcher'))
|
||||
);
|
||||
|
||||
this.subscription.add(
|
||||
this.devServer.run$
|
||||
.pipe(
|
||||
tap({
|
||||
complete: () => {
|
||||
// when the devServer gracefully exits because of an exit signal stop the cli dev mode to trigger full shutdown
|
||||
this.stop();
|
||||
},
|
||||
})
|
||||
)
|
||||
.subscribe(this.observer('dev server'))
|
||||
);
|
||||
}
|
||||
|
||||
private reportTimings(reporter: CiStatsReporter) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue