I want to run some analytics on my mail.log (postfix 3.2.13 on Ubuntu 20.04 LTS) including updating a db of undeliverable emails, so I wrote script, excluded mail.log from the generic /var/log logrotate script and created a new /etc/lorotate.d/mail_log which ran the script in the post-rotate section. Although the script was getting invoked, it was unable to generate the db file:
postfix/postmap[540039]: fatal: open /etc/postfix/bad_recipients.db: Read-only file system
Thinking that this might actually be a permissions issue, I added a sudoers rule for the syslog user (the /var/log/mail files are owned by syslog user) and amended the logrotate script:
/var/log/mail.log
{
rotate 30
daily
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
/usr/lib/rsyslog/rsyslog-rotate
sudo /usr/local/sbin/mailfail.sh
endscript
}
But I still get the same error reported at the top of each mail.log (Read-only file system
) and the database is not updated.
That the script is executing at all suggests its not a chroot or permissions or sudo misconfiguration issue on the script. The other files being written to have permissions for the syslog user (the user owning the log files).
Rsyslogd appears to be the only executable in the chain which is subject to an apparmor profile - but adding the path /etc/postfix* (rwk) to the profile and switching from enforce to complain had no impact on the error.
(running the script from the command works as expectd)