made goldilocks reload config on SIGHUP
This commit is contained in:
parent
528e58969e
commit
a625ee9db9
|
@ -41,15 +41,12 @@ function createStorage(filename, filetype) {
|
|||
}
|
||||
|
||||
function read() {
|
||||
return fs.readFileAsync(filename)
|
||||
.catch(function (err) {
|
||||
return fs.readFileAsync(filename).then(parse).catch(function (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
return '';
|
||||
}
|
||||
return PromiseA.reject(err);
|
||||
})
|
||||
.then(parse)
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
var result = {
|
||||
|
@ -253,25 +250,29 @@ function run(args) {
|
|||
var workers = {};
|
||||
var cachedConfig;
|
||||
|
||||
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) {
|
||||
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);
|
||||
});
|
||||
})
|
||||
.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);
|
||||
})
|
||||
;
|
||||
});
|
||||
});
|
||||
|
||||
cluster.on('online', function (worker) {
|
||||
|
|
Loading…
Reference in New Issue