swap active host on sigterm signal if host being stopped is currently active (#169)
diff --git a/provider/lib/utils.js b/provider/lib/utils.js
index 3e38e1a..57550ca 100644
--- a/provider/lib/utils.js
+++ b/provider/lib/utils.js
@@ -460,7 +460,21 @@
.then(activeHost => {
return utils.initActiveHost(activeHost);
})
- .then(resolve)
+ .then(() => {
+ process.on('SIGTERM', function onSigterm() {
+ if (utils.activeHost === utils.host) {
+ var redundantHost = utils.host === 'host0' ? 'host1' : 'host0';
+ utils.redisClient.hsetAsync(utils.redisHash, utils.redisKey, redundantHost)
+ .then(() => {
+ utils.redisClient.publish(utils.redisHash, redundantHost);
+ })
+ .catch(err => {
+ logger.error(method, err);
+ });
+ }
+ });
+ resolve();
+ })
.catch(err => {
reject(err);
});