Don't require running docker with `--init` to stop with ^C (#892)

pull/902/head
Florent 2 months ago committed by GitHub
parent 48a8af83fc
commit e84c420a37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -6,6 +6,8 @@
var log = require('app/server/lib/log');
var Promise = require('bluebird');
var os = require('os');
var cleanupHandlers = [];
var signalsHandled = {};
@ -65,8 +67,8 @@ function runCleanupHandlers() {
}
/**
* Internal helper to exit on a signal. It runs the cleanup handlers, and then re-sends the same
* signal, which will no longer get caught.
* Internal helper to exit on a signal. It runs the cleanup handlers, and then
* exits propagating the same signal code than the one caught.
*/
function signalExit(signal) {
var prog = 'grist[' + process.pid + ']';
@ -81,7 +83,12 @@ function signalExit(signal) {
log.info("Server %s exiting on %s", prog, signal);
process.removeListener(signal, dup);
delete signalsHandled[signal];
process.kill(process.pid, signal);
// Exit with the expected exit code for being killed by this signal.
// Unlike re-sending the same signal, the explicit exit works even
// in a situation when Grist is the init (pid 1) process in a container
// See https://github.com/gristlabs/grist-core/pull/830 (and #892)
const signalNumber = os.constants.signals[signal];
process.exit(process.pid, 128 + signalNumber);
});
}

Loading…
Cancel
Save