Merge pull request #1477 from thelounge/xpaw/graceful-quit
Gracefully quit on Ctrl+C
This commit is contained in:
commit
271948b0fb
@ -490,7 +490,7 @@ Client.prototype.names = function(data) {
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.quit = function() {
|
||||
Client.prototype.quit = function(signOut) {
|
||||
const sockets = this.sockets.sockets;
|
||||
const room = sockets.adapter.rooms[this.id];
|
||||
|
||||
@ -499,7 +499,10 @@ Client.prototype.quit = function() {
|
||||
const socket = sockets.connected[user];
|
||||
|
||||
if (socket) {
|
||||
if (signOut) {
|
||||
socket.emit("sign-out");
|
||||
}
|
||||
|
||||
socket.disconnect();
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ ClientManager.prototype.autoloadUsers = function() {
|
||||
_.difference(loaded, updatedUsers).forEach((name) => {
|
||||
const client = _.find(this.clients, {name: name});
|
||||
if (client) {
|
||||
client.quit();
|
||||
client.quit(true);
|
||||
this.clients = _.without(this.clients, client);
|
||||
log.info(`User ${colors.bold(name)} disconnected and removed`);
|
||||
}
|
||||
|
@ -115,6 +115,31 @@ module.exports = function() {
|
||||
new Identification((identHandler) => {
|
||||
manager.init(identHandler, sockets);
|
||||
});
|
||||
|
||||
// Handle ctrl+c and kill gracefully
|
||||
let suicideTimeout = null;
|
||||
const exitGracefully = function() {
|
||||
if (suicideTimeout !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Forcefully exit after 3 seconds
|
||||
suicideTimeout = setTimeout(() => process.exit(1), 3000);
|
||||
|
||||
log.info("Exiting...");
|
||||
|
||||
// Close all client and IRC connections
|
||||
manager.clients.forEach((client) => client.quit());
|
||||
|
||||
// Close http server
|
||||
server.close(() => {
|
||||
clearTimeout(suicideTimeout);
|
||||
process.exit(0);
|
||||
});
|
||||
};
|
||||
|
||||
process.on("SIGINT", exitGracefully);
|
||||
process.on("SIGTERM", exitGracefully);
|
||||
});
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user