-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added feature to reopen log files #16
base: master
Are you sure you want to change the base?
Conversation
…custom exit code.
@sebastianhoitz Can you add tests for this please? |
+1 But, does the old fd not need to be closed? |
@sebastianhoitz Ping. Any progress on those tests? |
Hi! Sorry, I just noticed your comment about the tests last week. I will look into writing tests for this this week so that we can get the pull request merged in! :) |
@indexzero Ok, I now added a small unit test that checks whether the "reopenLogs" event is emitted. However, I would like to add more in-depth checks (see the commented code if the files exist). What would be a good way to do this in your opinion? @colinmollenhour I now close the old file descriptors. Is this ok now? |
…into feature/reopenlogs * 'master' of https://github.com/nodejitsu/forever-monitor: (23 commits) [dist] Version bump. 1.2.1 [dist test] Update travis to test [email protected] [dist fix] Support [email protected] [dist] Version bump. 1.2.0 [fix test] Allow for commands that have `node` in their name. Fixes foreversd#7 [fix] Set `Monitor.prototype.inspect` to null to `util.inspect` doesnt return "undefined". Fixes foreversd#2. [fix] Dont spawn `kill` for Windows compatibility. Fixes foreversd#27. [minor] Style compliance. added conditional running check to prevent multiple re-starts Tweaking the childData so tests pass reset max counter, return useful data from crashed processes, misc. supporting logic [fix] Correctly set `watchIgnoreDotFiles`. Fixes foreversd#25. [minor test fix] JSHint compliance. Refeactor `test/plugins/watch-test.js` to avoid the possibility of a race. remove console.log stmt Test added for sending a child process a message Add send message support to a forked child process fix handling dir wildcards in .foreverignore [fix] Fix tests when all env vars are not displayed in a single stdout message. Fixed setting of signal for 'kill' command Added custom child stop signal support ...
I'm not 100% sure they even need to be closed, but it seems like they would need to be. Should be possible to test with lsof to see if there are extra file handles after a rotate. |
@sebastianhoitz what's the significance of exit code 13? |
@indexzero It is the signal code for "Broken Pipe" which would occur if the log file was moved or deleted. http://people.cs.pitt.edu/~alanjawi/cs449/code/shell/UnixSignals.htm |
+1 |
Is there any hint of progress on this? We'd quite like this feature. Also, why was |
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:
Your node.js app could handle this request like this:
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:
however then I have to somehow pass that Parent monitor PID to my application, which seems kinda bad, too. And because the child processes aren't forked, but rather spawned in a whole new process, they have no way to communicate with the parent process via
process.send
. Would it be possible to change the way forever spawns new childs so that they can send data to the parent monitor process?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!