@@ -40,34 +40,35 @@ function decorateWithHealthCheck(server, options) {
4040 } ) ;
4141}
4242
43- function decorateWithSigtermHandler ( server , options ) {
44- const { onSigterm , onShutdown, timeout, logger } = options ;
43+ function decorateWithSignalHandler ( server , options ) {
44+ const { signal , onSignal , onShutdown, timeout, logger } = options ;
4545
4646 stoppable ( server , timeout ) ;
4747
4848 const asyncServerStop = promisify ( server . stop ) . bind ( server ) ;
4949
5050 function cleanup ( ) {
5151 asyncServerStop ( )
52- . then ( ( ) => onSigterm ( ) )
52+ . then ( ( ) => onSignal ( ) )
5353 . then ( ( ) => onShutdown ( ) )
5454 . then ( ( ) => {
55- process . removeListener ( 'SIGTERM' , cleanup ) ;
56- process . kill ( process . pid , 'SIGTERM' ) ;
55+ process . removeListener ( signal , cleanup ) ;
56+ process . kill ( process . pid , signal ) ;
5757 } )
5858 . catch ( ( error ) => {
5959 logger ( 'error happened during shutdown' , error ) ;
6060 process . exit ( 1 ) ;
6161 } ) ;
6262 }
63- process . on ( 'SIGTERM' , cleanup ) ;
63+ process . on ( signal , cleanup ) ;
6464}
6565
6666function terminus ( server , options = { } ) {
6767 const healthChecks = options . healthChecks || { } ;
6868
69+ const signal = options . signal || 'SIGTERM' ;
6970 const timeout = options . timeout || 1000 ;
70- const onSigterm = options . onSigterm || noopResolves ;
71+ const onSignal = options . onSignal || options . onSigterm || noopResolves ;
7172 const onShutdown = options . onShutdown || noopResolves ;
7273
7374 const logger = options . logger || noop ;
@@ -77,8 +78,9 @@ function terminus(server, options = {}) {
7778 logger
7879 } ) ;
7980
80- decorateWithSigtermHandler ( server , {
81- onSigterm,
81+ decorateWithSignalHandler ( server , {
82+ signal,
83+ onSignal,
8284 onShutdown,
8385 timeout,
8486 logger
0 commit comments