Skip to content

Commit b876ac3

Browse files
committed
Add support for unix domain sockets and systems socket activation.
1 parent f39c963 commit b876ac3

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

coder-base/config.js.default

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
exports.listenIP = null; // All ips
2-
exports.listenPort = 80;
1+
// Listen can take different values :
2+
// - port number
3+
// - [port number, bind address] array
4+
// - unix socket path
5+
// - "systemd" for socket activation
6+
exports.listen = 80;
37

48
exports.cacheApps = true;
59

coder-base/config.js.localhost

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
exports.listenIP = '127.0.0.1';
2-
exports.httpListenPort = 8080;
1+
// Listen can take different values :
2+
// - port number
3+
// - [port number, bind address] array
4+
// - unix socket path
5+
// - "systemd" for socket activation
6+
exports.listen = [8080, '127.0.0.1'];
37

48
exports.cacheApps = true;
59

coder-base/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"bcrypt": "~0.7",
1515
"connect": "~3.0",
1616
"cookie": "~0.1",
17-
"express-params": "0.0.3"
17+
"systemd": "git+https://github.com/plietar/node-systemd.git"
1818
}
1919
}

coder-base/server.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var connect = require('connect');
3434
var session = require('express-session');
3535
var bodyParser = require('body-parser');
3636
var cookieParser = require('cookie-parser');
37+
var systemd = require('systemd')
3738

3839
global.config = require('./config');
3940
global.coderlib = require('./apps/coderlib/app');
@@ -234,8 +235,8 @@ var initSocketIO = function( server ) {
234235
// Allow front end console to receive server logs over a socket connection.
235236
// Note that util.log will still only go to stdout
236237
var origlog = console.log;
237-
console.log = function(d) {
238-
origlog.call( console, d );
238+
console.log = function() {
239+
origlog.apply( console, arguments );
239240
if ( io ) {
240241
io.set('log level', 1);
241242
var clients = io.sockets.clients();
@@ -333,12 +334,21 @@ coderapp.all( /^\/app\/(\w+)$/, function( req, res ) { apphandler( req, res, __
333334

334335

335336
var server = http.createServer(coderapp);
336-
server.listen(config.httpListenPort, config.listenIP);
337-
initSocketIO(server);
338337

339-
pingStatusServer();
338+
if (Array.isArray(config.listen))
339+
var listenfn = server.listen.bind(server, config.listen[0], config.listen[1]);
340+
else
341+
var listenfn = server.listen.bind(server, config.listen);
340342

341-
process.on('uncaughtException', function(err) {
342-
console.log('WARNING: unhandled exception: ' + err );
343+
listenfn(function() {
344+
initSocketIO(server);
345+
346+
pingStatusServer();
347+
348+
systemd.notify();
349+
350+
process.on('uncaughtException', function(err) {
351+
console.log('WARNING: unhandled exception: ' + err );
352+
});
343353
});
344354

0 commit comments

Comments
 (0)