nesquena / dante

Turn any ruby code into a daemon.
MIT License
313 stars 17 forks source link

Fixes and cleanup for `redirect_output`, `kill_pid`, `interrupt`, and `log` as well as tests. #2

Closed mckern closed 12 years ago

mckern commented 12 years ago

My previous patch to make interrupt cleaner was poorly thought out. interrupt will now only raise if :debug is set, otherwise it passes a logged message.

kill_pid now uses SIGTERM instead of SIGINT since stopping a daemon cleanly isn't actually the same as interrupting a running process from the terminal; SIGTERM is more appropriate than SIGINT in that context.

After changing the handling of SIGTERM in runner.rb, the test needed to be updated to accommodate the fact that SIGTERM is no longer processed as SIGINT. I've also rolled in a test to validate that SIGINT and SIGTERM are being handled differently. All tests now pass (though 'Daemon has started successfully' will be written to the console vis STDOUT now; not sure how to safely suppress it in the context of the tests).

log has also been changed so that all messages are logged, regardless of debug mode. This is more in-line with how C daemons work. I think that it could be refactored to use Logger but for now it will provide a relatively reliable audit trail for applications flapping.

redirect_output has been updated to use $stdout, $stderr, and $stdin instead of STDOUT, STDERR, and STDIN. The uppercase-constants are generally used to reset the lowercase-aliases after they've been changed so changing them is considered bad form. Oops.

nesquena commented 12 years ago

Awesome, thanks.