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() {
return fs.readFileAsync(filename)
.catch(function (err) {
if (err.code === 'ENOENT') {
return '';
}
return PromiseA.reject(err);
})
.then(parse)
;
return fs.readFileAsync(filename).then(parse).catch(function (err) {
if (err.code === 'ENOENT') {
return '';
}
return PromiseA.reject(err);
});
}
var result = {
@ -253,25 +250,29 @@ function run(args) {
var workers = {};
var cachedConfig;
function updateConfig(config) {
fillConfig(config, args).then(function (config) {
cachedConfig = config;
console.log('changed config', config);
Object.keys(workers).forEach(function (key) {
workers[key].send(cachedConfig);
});
});
}
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(function (config) {
return fillConfig(config, args);
})
.then(function (config) {
cachedConfig = config;
console.log('changed config', config);
Object.keys(workers).forEach(function (key) {
workers[key].send(cachedConfig);
});
})
.catch(function (err) {
console.error('error changing config', err);
})
;
configStorage.save(message.changes).then(updateConfig).catch(function (err) {
console.error('error changing config', err);
});
});
cluster.on('online', function (worker) {