How can Dancer app process HUP signal to close/reopen logfile

520 Views Asked by At

I wrote a Dancer app, with the log config:

logger:       file
logger_format: <%T> %m
log_path:     '/usr/local/myapp/log'
log_file:     'myapp.log'
log:          debug

and start it with:

plackup -E deployment -D -s Starman --workers=10 --port 8080 -a bin/app.pl

rotate the log file with logrotate

/usr/local/myapp/log/myapp.log {
    daily
    rotate 10
    create 0660 root root
    compress
    missingok
    dateext
}

but the new logfile is zero.

I tried to add postrotate in logrotate conf to send HUP and process HUP sinal in bin/app.pl with

Dancer::Logger::File::init;

but nothing help.

Can anyone tell me how to rotate the dancer's logfile?

1

There are 1 best solutions below

0
On

One solution to let this happen is that plackup supports the -R switch to watch a folder, so you could add -R <appdir>/run and then change logrotate to:

postrotate
  touch <appdir>/run/last.run

As far as I can tell though what you want can't be done in this configuration. Starman explicitly handles sighup to restart the child processes. From Starman/Server.pm:

24 # Override Net::Server's HUP handling - just restart all the workers and that's about it
25 sub sig_hup {
26     my $self = shift;
27     $self->hup_children;
28 }

Perhaps you need an alternative logging solution such as using Dancer::Logger::Syslog

Or, if you must write to a file, maybe check for changes with Linux::Inotify2