Skip to content

Commit 2519526

Browse files
committed
Add support for automatic quit when idle for a long time.
1 parent b876ac3 commit 2519526

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

coder-base/config.js.default

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
// - "systemd" for socket activation
66
exports.listen = 80;
77

8+
// Automatically stop the server if idle for a long amount of time.
9+
// Designed to be used in conjunction with listen = "systemd".
10+
// Disabled if timeout is 0
11+
exports.idleTimeout = 0;
12+
813
exports.cacheApps = true;
914

1015
//Experimental

coder-base/config.js.localhost

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
// - "systemd" for socket activation
66
exports.listen = [8080, '127.0.0.1'];
77

8+
// Automatically stop the server if idle for a long amount of time.
9+
// Designed to be used in conjunction with listen = "systemd".
10+
// Disabled if timeout is 0
11+
exports.idleTimeout = 0;
12+
813
exports.cacheApps = true;
914

1015
//Experimental

coder-base/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"bcrypt": "~0.7",
1515
"connect": "~3.0",
1616
"cookie": "~0.1",
17-
"systemd": "git+https://github.com/plietar/node-systemd.git"
17+
"systemd": "git+https://github.com/plietar/node-systemd.git",
18+
"autoquit": "~0.1.6"
1819
}
1920
}

coder-base/server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var session = require('express-session');
3535
var bodyParser = require('body-parser');
3636
var cookieParser = require('cookie-parser');
3737
var systemd = require('systemd')
38+
require('autoquit');
3839

3940
global.config = require('./config');
4041
global.coderlib = require('./apps/coderlib/app');
@@ -334,6 +335,9 @@ coderapp.all( /^\/app\/(\w+)$/, function( req, res ) { apphandler( req, res, __
334335

335336

336337
var server = http.createServer(coderapp);
338+
if (config.idleTimeout) {
339+
server.autoQuit({ timeOut: config.idleTimeout });
340+
}
337341

338342
if (Array.isArray(config.listen))
339343
var listenfn = server.listen.bind(server, config.listen[0], config.listen[1]);

0 commit comments

Comments
 (0)