Files
cloudron-box/box.js
T

67 lines
1.9 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
'use strict';
2018-10-22 11:39:42 -07:00
let async = require('async'),
2018-08-13 21:10:53 +02:00
dockerProxy = require('./src/dockerproxy.js'),
2020-08-04 09:34:03 -07:00
fs = require('fs'),
2019-07-26 15:01:47 -07:00
ldap = require('./src/ldap.js'),
2020-08-04 09:34:03 -07:00
paths = require('./src/paths.js'),
2020-11-10 09:59:28 -08:00
proxyAuth = require('./src/proxyauth.js'),
server = require('./src/server.js');
2020-08-04 09:34:03 -07:00
const NOOP_CALLBACK = function () { };
function setupLogging(callback) {
2020-08-04 22:16:38 -07:00
if (process.env.BOX_ENV === 'test') return callback();
var logfileStream = fs.createWriteStream(paths.BOX_LOG_FILE, { flags:'a' });
process.stdout.write = process.stderr.write = logfileStream.write.bind(logfileStream);
2020-08-04 09:34:03 -07:00
callback();
2020-08-04 09:34:03 -07:00
}
2015-09-14 10:52:11 -07:00
async.series([
2020-08-04 09:34:03 -07:00
setupLogging,
2020-11-09 20:34:48 -08:00
server.start, // do this first since it also inits the database
2020-11-10 09:59:28 -08:00
proxyAuth.start,
2015-09-14 10:52:11 -07:00
ldap.start,
2018-10-22 11:39:42 -07:00
dockerProxy.start
2015-09-14 10:52:11 -07:00
], function (error) {
if (error) {
2020-08-04 09:34:03 -07:00
console.log('Error starting server', error);
process.exit(1);
}
// require those here so that logging handler is already setup
require('supererror');
const debug = require('debug')('box:box');
2020-08-04 09:34:03 -07:00
process.on('SIGINT', function () {
debug('Received SIGINT. Shutting down.');
2018-11-08 14:35:22 +01:00
2020-11-10 09:59:28 -08:00
proxyAuth.stop(NOOP_CALLBACK);
2020-08-04 09:34:03 -07:00
server.stop(NOOP_CALLBACK);
ldap.stop(NOOP_CALLBACK);
dockerProxy.stop(NOOP_CALLBACK);
setTimeout(process.exit.bind(process), 3000);
});
process.on('SIGTERM', function () {
debug('Received SIGTERM. Shutting down.');
2015-09-09 16:57:41 -07:00
2020-11-10 09:59:28 -08:00
proxyAuth.stop(NOOP_CALLBACK);
2020-08-04 09:34:03 -07:00
server.stop(NOOP_CALLBACK);
ldap.stop(NOOP_CALLBACK);
dockerProxy.stop(NOOP_CALLBACK);
setTimeout(process.exit.bind(process), 3000);
});
2018-11-08 14:35:22 +01:00
process.on('uncaughtException', function (error) {
console.error((error && error.stack) ? error.stack : error);
setTimeout(process.exit.bind(process, 1), 3000);
});
2020-08-04 09:34:03 -07:00
console.log(`Cloudron is up and running. Logs are at ${paths.BOX_LOG_FILE}`); // this goes to journalctl
2015-09-09 16:57:41 -07:00
});