Skip to content

Commit

Permalink
[fix] Remove .fvr file when a forever.Monitor child exits
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed May 31, 2011
1 parent 4e84d71 commit 1af1fe3
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/forever/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var Monitor = exports.Monitor = function (script, options) {
this.options = options.options || [];
this.spawnWith = options.spawnWith || null;
this.uid = options.uid || forever.randomString(24);
this.fvrFile = path.join(forever.config.get('pidPath'), this.uid + '.fvr');
this.max = options.max;
this.logFile = options.logFile || path.join(forever.config.get('root'), this.uid + '.log');
this.pidFile = options.pidFile || path.join(forever.config.get('pidPath'), this.uid + '.pid');
Expand Down Expand Up @@ -149,8 +150,10 @@ Monitor.prototype.start = function (restart) {
if (self.stdout) self.stdout.end();
// If had to write to an stderr file, close it
if (self.stderr) self.stderr.end();

self.emit('exit', self, spinning);

fs.unlink(self.fvrFile, function () {
self.emit('exit', self, spinning);
});
}

function restartChild() {
Expand All @@ -161,7 +164,7 @@ Monitor.prototype.start = function (restart) {
});
}

if(self.forceStop) {
if (self.forceStop) {
letChildDie();
}
else if(spinning && typeof self.spinSleepTime !== 'number') {
Expand All @@ -170,7 +173,7 @@ Monitor.prototype.start = function (restart) {
else if (!self.forever && self.times >= self.max) {
letChildDie();
}
else if(spinning) {
else if (spinning) {
setTimeout(restartChild, self.spinSleepTime);
}
else {
Expand Down Expand Up @@ -234,10 +237,8 @@ Monitor.prototype.save = function () {
childData.file = childData.file.replace(this.sourceDir + '/', '');
}

var childPath = path.join(forever.config.get('pidPath'), this.uid + '.fvr');
fs.writeFile(childPath, JSON.stringify(childData, null, 2), function (err) {
if (err) self.emit('error', err);
self.emit('save', childPath, childData);
fs.writeFile(this.fvrFile, JSON.stringify(childData, null, 2), function (err) {
return err ? self.emit('error', err) : self.emit('save', self.fvrFile, childData);
});

//
Expand Down

0 comments on commit 1af1fe3

Please sign in to comment.