Skip to content

Commit

Permalink
Implement a control socket
Browse files Browse the repository at this point in the history
Ref #1643
  • Loading branch information
strugee committed Jun 19, 2018
1 parent 3c2f8c5 commit e9951de
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
21 changes: 21 additions & 0 deletions bin/pump
Expand Up @@ -27,9 +27,11 @@ var cluster = require("cluster"),
os = require("os"),
fs = require("fs"),
path = require("path"),
net = require("net"),
Logger = require("bunyan"),
_ = require("lodash"),
importFresh = require("import-fresh"),
split = require("split"),
configUtil = require("../lib/config"),
restartEpoch = require("../lib/zerodowntime"),
restartInflight = false,
Expand Down Expand Up @@ -143,6 +145,25 @@ var launchApps = function(configBase) {
cluster.fork();
});

var ctl = net.createServer(function(con) {
con.pipe(split()).on("data", function(line) {
switch (line.toLowerCase()) {
case "restart":
triggerRestart(clusterLog, config);
con.write("ACK\n");
clusterLog.info("Received command over control socket.", line);
break;
default:
clusterLog.info("Received unknown command over control socket; reject.", line);
con.write("NACK\n");
}
});
});

ctl.listen(config.controlSocket, function() {
clusterLog.info("Listening for control commands on " + config.controlSocket + ".");
});

// Perform zero-downtime restart on SIGUSR2
// TODO handle config changes
process.on("SIGUSR2", triggerRestart.bind(null, clusterLog, config));
Expand Down
3 changes: 2 additions & 1 deletion lib/defaults.js
Expand Up @@ -81,5 +81,6 @@ module.exports = {driver: "memory",
cleanupSession: 1200000,
cleanupNonce: 1200000,
favicon: path.resolve(__dirname, "../public/images/favicon.ico"),
users: []
users: [],
controlSocket: "/run/pump.socket"
};
87 changes: 87 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -56,6 +56,7 @@
"serve-favicon": "^2.3.0",
"showdown": "^1.4.1",
"sockjs": "0.3.x",
"split": "^1.0.1",
"ssl-config": "^1.0.0",
"step": "^1.0.0",
"ua-parser-js": "^0.7.10",
Expand Down

0 comments on commit e9951de

Please sign in to comment.