-
Notifications
You must be signed in to change notification settings - Fork 4
/
backends.js
26 lines (24 loc) · 944 Bytes
/
backends.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var dockerActivator = require('docker-activator'),
indiehosters = require('indiehosters-applications'),
alarm = require('./alarm'),
lastCheck = 0,
MAX_IDLE_TIME = 7 * 24 * 3600 * 1000;
module.exports.init = function() {
console.log('initializing backends...');
dockerActivator.init(function(err) {
console.log('dockerActivator init', err);
});
}
module.exports.ensureStarted = function(host, config, callback) {
var now = new Date().getTime();
var dockerOptions = indiehosters.getDockerOptions(host, config.application, config.backendEnv, 200, '/data/domains/' + host);
alarm.debug('dockerOptions', host, config, dockerOptions);
dockerActivator.ensureStarted(dockerOptions, callback);
if (now - lastCheck > 6000 * 1000) {
console.log('clean up check');
lastCheck = now;
dockerActivator.maybeStopOneContainer(MAX_IDLE_TIME, '', function(err) {
console.log('clean up', err);
});
}
};