nodejitsu/forever-monitor — pull request #16 by sebastianhoitz (2013-01-08 20:39:25+00:00)
Title: Added feature to reopen log files

This functionality is especially useful when you want to implement a logrotate functionality with native tools like **logrotate**.

## Example implementation

After rotating the logs, you could send your process a custom SIGUSR2 signal:

```bash
$ kill -SIGUSR2 **PID**
```

Your node.js app could handle this request like this:

```javascript
process.on("SIGUSR2", function() {
console.log("Received SIGUSR2 signal. Stopping application");
process.exit(13); // Notice this exit code. This tells forever that the script wants to reopen its log files.
});
```

Forever now checks the exit code of the child process that died. When it is **13**, it creates a new filedescriptor for the process.stdout stream.

## Improvement
While I feel that the event-based notification within forever is pretty good, I don't like the communication between the child-process and forever yet.

However I could not get the child to notify forever-monitor in a better way.

I was thinking about letting the monitor process know via sending a SIGUSR2 command to the process from my app like this:

```javascript
process.on("SIGUSR2", function() {
console.log("Received SIGUSR2 signal. Stopping application");
process.kill(PARENT_MONITOR_PID, "SIGUSR2"); // Notice this exit code. This tells forever that the script wants to reopen its log files.
});
```

however then I have to somehow pass that Parent monitor PID to my application, which seems kinda bad, too.

---------------

So yes, there is room for improvement. But because of lack of knowledge with forever I was not able to do this any better. Please let me know what you think!