made goldilocks reload config on SIGHUP

This commit is contained in:
tigerbot 2017-09-19 18:23:43 -06:00
parent 528e58969e
commit a625ee9db9
1 changed files with 25 additions and 24 deletions

View File

@ -41,15 +41,12 @@ function createStorage(filename, filetype) {
} }
function read() { function read() {
return fs.readFileAsync(filename) return fs.readFileAsync(filename).then(parse).catch(function (err) {
.catch(function (err) {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT') {
return ''; return '';
} }
return PromiseA.reject(err); return PromiseA.reject(err);
}) });
.then(parse)
;
} }
var result = { var result = {
@ -253,25 +250,29 @@ function run(args) {
var workers = {}; var workers = {};
var cachedConfig; var cachedConfig;
cluster.on('message', function (worker, message) { function updateConfig(config) {
if (message.type !== 'com.daplie.goldilocks/config') { fillConfig(config, args).then(function (config) {
return;
}
configStorage.save(message.changes)
.then(function (config) {
return fillConfig(config, args);
})
.then(function (config) {
cachedConfig = config; cachedConfig = config;
console.log('changed config', config); console.log('changed config', config);
Object.keys(workers).forEach(function (key) { Object.keys(workers).forEach(function (key) {
workers[key].send(cachedConfig); workers[key].send(cachedConfig);
}); });
}) });
.catch(function (err) { }
process.on('SIGHUP', function () {
configStorage.read().then(updateConfig).catch(function (err) {
console.error('error updating config after SIGHUP', err);
});
});
cluster.on('message', function (worker, message) {
if (message.type !== 'com.daplie.goldilocks/config') {
return;
}
configStorage.save(message.changes).then(updateConfig).catch(function (err) {
console.error('error changing config', err); console.error('error changing config', err);
}) });
;
}); });
cluster.on('online', function (worker) { cluster.on('online', function (worker) {