From 1af1fe3cc48f8d23829cfd1db5a5abd313e2c50c Mon Sep 17 00:00:00 2001 From: indexzero Date: Tue, 31 May 2011 10:26:38 -0400 Subject: [PATCH] [fix] Remove .fvr file when a forever.Monitor child exits --- lib/forever/monitor.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/forever/monitor.js b/lib/forever/monitor.js index 6fef3aa0..cb0c51ba 100644 --- a/lib/forever/monitor.js +++ b/lib/forever/monitor.js @@ -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'); @@ -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() { @@ -161,7 +164,7 @@ Monitor.prototype.start = function (restart) { }); } - if(self.forceStop) { + if (self.forceStop) { letChildDie(); } else if(spinning && typeof self.spinSleepTime !== 'number') { @@ -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 { @@ -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); }); //