import chalk from 'chalk' ; import { CliArgs , Env , RawConfigService } from './config' ; import { Root } from './root' ; import { CriticalError } from './errors' ; interface BootstrapArgs { configs : string [ ] ; cliArgs : CliArgs ; applyConfigOverrides : ( config : Record < string , any > ) => Record < string , any > ; } internal param param0 export async function bootstrap ( { configs , cliArgs , applyConfigOverrides } ) { if ( cliArgs . optimize ) { return ; } const { REPO_ROOT } = require ( '@kbn/utils' ) ; const env = Env . createDefault ( REPO_ROOT , { configs , cliArgs , } ) ; const rawConfigService = new RawConfigService ( env . configs , applyConfigOverrides ) ; rawConfigService . loadConfig ( ) ; const root = new Root ( rawConfigService , env , onRootShutdown ) ; process . on ( 'SIGHUP' , ( ) => reloadConfiguration ( ) ) ; process . on ( 'message' , ( msg ) => { if ( ! msg || msg . reloadConfiguration !== true ) { return ; } reloadConfiguration ( ) ; } ) ; function reloadConfiguration ( reason = 'SIGHUP signal received' ) { const cliLogger = root . logger . get ( 'cli' ) ; cliLogger . info ( `Reloading Kibana configuration (reason: ${ reason }).` , { tags : [ 'config' ] } ) ; try { rawConfigService . reloadConfig ( ) ; } catch ( err ) { return shutdown ( err ) ; } cliLogger . info ( `Reloaded Kibana configuration (reason: ${ reason }).` , { tags : [ 'config' ] } ) ; } process . on ( 'SIGINT' , ( ) => shutdown ( ) ) ; process . on ( 'SIGTERM' , ( ) => shutdown ( ) ) ; function shutdown ( reason ? ) { rawConfigService . stop ( ) ; return root . shutdown ( reason ) ; } try { const { preboot } = await root . preboot ( ) ; const isSetupOnHold = preboot . isSetupOnHold ( ) ; if ( process . send && isSetupOnHold ) { process . send ( [ 'SERVER_LISTENING' ] ) ; } if ( isSetupOnHold ) { root . logger . get ( ) . info ( 'Holding setup until preboot stage is completed.' ) ; const { shouldReloadConfig } = await preboot . waitUntilCanSetup ( ) ; if ( shouldReloadConfig ) { await reloadConfiguration ( 'configuration might have changed during preboot stage' ) ; } } await root . setup ( ) ; await root . start ( ) ; if ( process . send && ! isSetupOnHold ) { process . send ( [ 'SERVER_LISTENING' ] ) ; } } catch ( err ) { await shutdown ( err ) ; } } function onRootShutdown ( reason ? ) { if ( reason !== undefined ) { console . error ( `\n${ chalk . white . bgRed ( ' FATAL ' ) } ${ reason }\n` ) ; process . exit ( reason instanceof CriticalError ? reason . processExitCode : 1 ) ; } process . exit ( 0 ) ; }