initially, i thought i can hardcode the log file into taskworker.js depending on the task type but for apptask, it's not easy to get the appId from the taskId unless we introspect task arguments as well. it's easier for now to pass it as an argument.
62 lines
1.6 KiB
JavaScript
Executable File
62 lines
1.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
'use strict';
|
|
|
|
let async = require('async'),
|
|
dockerProxy = require('./src/dockerproxy.js'),
|
|
fs = require('fs'),
|
|
ldap = require('./src/ldap.js'),
|
|
paths = require('./src/paths.js'),
|
|
server = require('./src/server.js'),
|
|
util = require('util');
|
|
|
|
const NOOP_CALLBACK = function () { };
|
|
|
|
function setupLogging(callback) {
|
|
if (process.env.BOX_ENV === 'test') return callback();
|
|
|
|
fs.open(paths.BOX_LOG_FILE, 'a', function (error, fd) {
|
|
if (error) return callback(error);
|
|
|
|
require('debug').log = function (...args) {
|
|
fs.appendFileSync(fd, util.format(...args) + '\n');
|
|
};
|
|
|
|
callback();
|
|
});
|
|
}
|
|
|
|
async.series([
|
|
setupLogging,
|
|
server.start,
|
|
ldap.start,
|
|
dockerProxy.start
|
|
], function (error) {
|
|
if (error) {
|
|
console.log('Error starting server', error);
|
|
process.exit(1);
|
|
}
|
|
|
|
const debug = require('debug')('box:box'); // require this here so that logging handler is already setup
|
|
|
|
process.on('SIGINT', function () {
|
|
debug('Received SIGINT. Shutting down.');
|
|
|
|
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.');
|
|
|
|
server.stop(NOOP_CALLBACK);
|
|
ldap.stop(NOOP_CALLBACK);
|
|
dockerProxy.stop(NOOP_CALLBACK);
|
|
setTimeout(process.exit.bind(process), 3000);
|
|
});
|
|
|
|
console.log(`Cloudron is up and running. Logs are at ${paths.BOX_LOG_FILE}`); // this goes to journalctl
|
|
});
|