fix(bootstrap): C-c twice force stop the server

This commit is contained in:
Julien Fontanet 2016-09-27 10:44:24 +02:00
parent 50584c2e50
commit 9f66421ae7

View File

@ -608,16 +608,24 @@ export default async function main (args) {
await registerPlugins(xo) await registerPlugins(xo)
} }
// Gracefully shutdown on signals.
//
// TODO: implements a timeout? (or maybe it is the services launcher // TODO: implements a timeout? (or maybe it is the services launcher
// responsibility?) // responsibility?)
const shutdown = signal => { forEach([ 'SIGINT', 'SIGTERM' ], signal => {
debug('%s caught, closing…', signal) let alreadyCalled = false
xo.stop()
}
// Gracefully shutdown on signals. process.on(signal, () => {
process.on('SIGINT', () => shutdown('SIGINT')) if (alreadyCalled) {
process.on('SIGTERM', () => shutdown('SIGTERM')) warn('forced exit')
process.exit(1)
}
alreadyCalled = true
debug('%s caught, closing…', signal)
xo.stop()
})
})
await eventToPromise(xo, 'stopped') await eventToPromise(xo, 'stopped')