Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
check signal instead of code for restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Hall committed Jan 11, 2017
1 parent a09ace0 commit 6b4073a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ class RPC {
});

// NB: Listen for exits and restart the share if not stopped manually
share.process.on('exit', (code) => {
share.process.on('exit', (code, signal) => {
let maxRestartsReached = share.meta.numRestarts >= RPC.MAX_RESTARTS;
share.readyState = RPC.SHARE_STOPPED;

self._log(`share ${nodeId} exited with code ${code}`);
clearInterval(uptimeCounter);

if (code !== 0 && share.meta.numRestarts < RPC.MAX_AUTO_RESTARTS) {
if (signal !== 'SIGKILL' && !maxRestartsReached) {
share.meta.numRestarts++;
self.restart(nodeId, () => null);
}
Expand Down Expand Up @@ -256,6 +258,6 @@ class RPC {
RPC.SHARE_STARTED = 1;
RPC.SHARE_STOPPED = 0;
RPC.SHARE_ERRORED = 2;
RPC.MAX_AUTO_RESTARTS = 30;
RPC.MAX_RESTARTS = 30;

module.exports = RPC;

0 comments on commit 6b4073a

Please sign in to comment.