# We don't want to reload twice (for each log file), so we use the sharedscripts
# option.  This means that hitcounter is run only once too (which is good).  In
# (likely impossible) situations when access.log is empty and error.log not, we
# would call hitcounter too on an empty file.
#
# Note that lighttpd server runs with max-workers, and thus we should pipe the
# logs through cronolog to have consistent logs (see mod_accesslog docs).  On
# the other hand, we still use logrotate.  That's needed because it supports
# compressison, and because it can trigger the hitcounter script below.
#
# Running both "log rotation" programs turned out to be very complicated:
# - sending -HUP to lighty doesn't restart the piped cronolog, so it never
#   reopens the file after rotation
# - cronolog doesn't handle -HUP correctly, it just terminates
# - when cronolog terminates, lighttpd restarts all the child processes (not
#   just cronolog processes), leading to whole bunch of problems (but there's at
#   least short downtime)
# There's no reasonable way-around this than logrotate's copytruncate option
# (which is racy by definition).  Lighty is innocent here (doesn't ever expect
# the log pipe to terminate, and if it happens it's good reason to restart
# everything).  Cronolog is innocent here, it doesn't actaully do any rotation.
# Lograte is innocent as well.
# See https://pagure.io/copr/copr/issue/2001 for more info.

/var/log/lighttpd/*log {
    rotate 5
    daily
    missingok
    notifempty
    compress
    delaycompress
    sharedscripts
    prerotate
        /usr/bin/copr_log_hitcounter.py /var/log/lighttpd/access.log &>>/var/log/copr-backend/hitcounter-logrotate.log || :
    endscript
    postrotate
        /usr/local/bin/copr-lighty-reopen-logs || :
    endscript
}
