-
Notifications
You must be signed in to change notification settings - Fork 84
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
How to reopen error log for rotation ? #55
Comments
Would like to know this too. Need a signal number to send, or some run flag, or something else. And this function (log file reopen) should not delay requests processing and i suppose should not force starman to reread psgi app. |
Just since you guys were asking "how" - the answer is that it's not supported as of currently. |
Thanks Tatsuhiko! "Not supported" is enough for "how to". |
I'm looking at implementing a workaround to do this using the pluggable logging facility of Starman::Server's base class Net::Server in combination with Log::Log4perl's ability to re-open log files via the Log::Log4perl::Appender::File recreate_check_signal option. However, this requires passing command line parameters that Net::Server can access and Starman::Server->run doesn't pass them on. (starman passes unknown parameters to Plack::Runner and they get stored as key value pairs in $self->{options} but they don't make it to Net::Server which expects them in $self->{server}.) I put a rather broad hack in that works for me but my setup doesn't really exercise all of the command line parameters so I'm not sure if the hack breaks anything else. I tried to run it against the test suite using "cpanm --look starman" but I don't know my way around the build dir structure well enough to get anything done and there weren't any instructions. Here is the diff if you're interested: *** lib/Starman/Server.pm 2013-04-06 22:04:57.000000000 -0700
--- lib/Starman/Server.new.pm 2013-04-17 11:14:23.121528622 -0700
***************
*** 66,69 ****
--- 67,74 ----
$self->SUPER::run(
+ # Pass all raw command line options to our parent Which expects them
+ # here. Any that need to be modified by our option parsing get
+ # clobbered below
+ %$options,
port => $port,
host => $host, |
Could we not simply change the logging so it closes/reopens the filehandle on every write? This file doesn't usually get written to that often, so it wouldn't be inefficient. |
@karenetheridge that would be one approach to adding this functionality. So would just re-opening the handle on HUP. But, Net::Server doesn't offer an API for directly affecting the filehandle. The filehandle itself appears to be intended as private so I am hesitant to add code that depends upon it's implementation. One alternative would be to override the methods that access the filehandle, however those are big methods and it seemed like that couldn't be done easily without a lot of copy pasta. Another alternative would be to submit a patch to Net::Server that exposed the filehandle for fiddling. I opted for the code I shared above because it's changes far fewer lines of code, uses the parent's exposed API and adds exposure to other parts of the parent's API. The downside is that the pluggable logging does require more configuration up-front. |
@benrifkah I know you want to use Log4perl et al, but just as a FYI, we use this setup at $work:
|
@lestrrat that is a great way to ensure that the ACCESS log gets rotated. It is similar to what we're doing with Log4perl. However, I think you'll find that it doesn't work for the ERROR log which is what this thread is about. Since the error log filehandle is owned by Net::Server which isn't aware of Plack::Builder it would take breaking some API boundaries to make it configurable via middleware. |
@benrifkah Oh I see. My bad. Again, just FYI we don't worry about doing error log locations because we just print it to STDERR and let daemontools' multilog handle the log management. |
On log rotation Starman/Plack keeps failing (Auth.pm related problems) due to permission issues: Could not compile /usr/share/koha/opac/cgi-bin/opac/opac-search.pl: Can't locate Authen/CAS/Client/Response/Failure.pm : ./Authen/CAS/Client/Response/Failure.pm: Permission denied at /usr/share/perl/5.20/base.pm line 97. ...propagated at /usr/share/perl/5.20/base.pm line 106. BEGIN failed--compilation aborted at /usr/share/perl5/Authen/CAS/Client/Response.pm line 68. Compilation failed in require at /usr/share/perl5/Authen/CAS/Client.pm line 8. BEGIN failed--compilation aborted at /usr/share/perl5/Authen/CAS/Client.pm line 8. Compilation failed in require at /usr/share/koha/lib/C4/Auth_with_cas.pm line 25. BEGIN failed--compilation aborted at /usr/share/koha/lib/C4/Auth_with_cas.pm line 25. Compilation failed in require at /usr/share/koha/lib/C4/Auth.pm line 63. BEGIN failed--compilation aborted at /usr/share/koha/lib/C4/Auth.pm line 90. Compilation failed in require at /usr/share/koha/opac/cgi-bin/opac/opac-search.pl line 34. BEGIN failed--compilation aborted at /usr/share/koha/opac/cgi-bin/opac/opac-search.pl line 34. As we do with zebra daemons, starman should be restarted as it doesn't handle log file rotation gracefully[1]. I'm not sure how to reproduce it on a dev environment. [1] miyagawa/Starman#55 Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
On log rotation Starman/Plack keeps failing (Auth.pm related problems) due to permission issues: Could not compile /usr/share/koha/opac/cgi-bin/opac/opac-search.pl: Can't locate Authen/CAS/Client/Response/Failure.pm : ./Authen/CAS/Client/Response/Failure.pm: Permission denied at /usr/share/perl/5.20/base.pm line 97. ...propagated at /usr/share/perl/5.20/base.pm line 106. BEGIN failed--compilation aborted at /usr/share/perl5/Authen/CAS/Client/Response.pm line 68. Compilation failed in require at /usr/share/perl5/Authen/CAS/Client.pm line 8. BEGIN failed--compilation aborted at /usr/share/perl5/Authen/CAS/Client.pm line 8. Compilation failed in require at /usr/share/koha/lib/C4/Auth_with_cas.pm line 25. BEGIN failed--compilation aborted at /usr/share/koha/lib/C4/Auth_with_cas.pm line 25. Compilation failed in require at /usr/share/koha/lib/C4/Auth.pm line 63. BEGIN failed--compilation aborted at /usr/share/koha/lib/C4/Auth.pm line 90. Compilation failed in require at /usr/share/koha/opac/cgi-bin/opac/opac-search.pl line 34. BEGIN failed--compilation aborted at /usr/share/koha/opac/cgi-bin/opac/opac-search.pl line 34. As we do with zebra daemons, starman should be restarted as it doesn't handle log file rotation gracefully[1]. I'm not sure how to reproduce it on a dev environment. [1] miyagawa/Starman#55 Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com> (cherry picked from commit 93efeab) Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Actually, is this even needed? You can create a "Net::Server::Log::MyClass" class that handles the logging, and then for the error-log parameter pass "MyClass". It works. |
What is the right way to reopen log file (--error-log) for graceful rotation ?
The text was updated successfully, but these errors were encountered: