Rotation of logs (logrotate) and releasing the rotated inode log file
fauust opened this issue · 3 comments
Hi!
I have configured mirrorbits as a systemd service like bellow:
[Unit]
Description=Mirrorbits redirector
Documentation=https://github.com/etix/mirrorbits
After=network.target
[Service]
Type=fork
RuntimeDirectory=mirrorbits
User=www-data
PIDFile=/run/mirrorbits/mirrorbits.pid
ExecStart=/usr/local/bin/mirrorbits daemon -p /run/mirrorbits/mirrorbits.pid
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=-/bin/kill -QUIT $MAINPID
KillMode=mixed
Restart=on-failure
[Install]
WantedBy=multi-user.target
The logs are configured like follow:
❯ grep ^LogDir /etc/mirrorbits.conf
LogDir: /var/log/mirrorbits
And finally I have tried the following logrotate conf:
❯ cat /etc/logrotate.d/mirrorbits
/var/log/mirrorbits/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
postrotate
/usr/bin/killall -HUP mirrorbits
endscript
}
My problem is that reloading mirrorbits (with /usr/bin/killall -HUP mirrorbits
) is not sufficient to release inode log file and mirrorbits continue to write logs to the rotated file (that was kind of expected as the documentation says that it will only "reload configuration"):
❯ ls -l /var/log/mirrorbits
total 68184
-rw-r----- 1 www-data adm 0 Mar 30 00:00 downloads.log
-rw-r----- 1 www-data adm 2659979 Mar 30 10:02 downloads.log.1
-rw-r----- 1 www-data adm 2854980 Mar 29 11:08 downloads.log.2.gz
If possible I would like to avoid restarting mirrorbits on every log rotation but I am not sure if that's possible.
you want "copytruncate"
try this:
/var/log/mirrorbits/*.log {
notifempty
missingok
daily
dateext
compress
copytruncate
rotate 7
}
Wow thanks, that was easier than I thought, sorry for not RTFM of logrotate, I was blind by the nginx logrotate configuration.
I will close this tomorrow if it works.