Logrotate is rotating the file, but not signaling your Python script when
this happens. So yes, as you have noticed, the rotation will not work
correctly with this setup.

You have two options. First and preferred option I think: forget about
logrotate and make your Python script rotate the logs by itself. I see the
Python logging library already has support for this:
https://docs.python.org/3/library/logging.handlers.html#rotatingfilehandler

This simplifies things since you no longer have to synchronize two
processes (logrotate and your script).

The second option would be to use logrotate and:
- configure the postrotate script to send a HUP signal to rsyslog
- in rsyslog, configure the 'hup.signal' flag of omprog to forward the HUP
signal to your script
- in your Python script, handle the HUP signal by reopening the log file

Regards

Joan


On Tue, May 26, 2020, 05:58 Fourhundred Thecat via rsyslog <
[email protected]> wrote:

> Hello,
>
> in my /etc/rsyslog.conf, I am calling external script to handle
> mail.* logging:
>
> mail.*        action(type="omprog" name="blacklist-postfix"
> binary="/usr/local/sbin/postfix.py" template="long-iso")
>
> This custom script processes logs, and writes to /var/log/mail/mail.log
>
> Everything works well, except my logs are not being logrotated properly.
> This is my logrotate config:
>
> /var/log/mail/mail.log {
>      rotate 4
>      weekly
>      sharedscripts
>      postrotate
>          invoke-rc.d rsyslog rotate > /dev/null
>      endscript
> }
>
> I suspect, the problem is that "invoke-rc.d rsyslog rotate" does rotate
> rsyslog, but not my external script.
>
> What would be the proper way to handle this?
> Do I have to restart rsyslog, so that my script is terminated and
> started anew?
> _______________________________________________
> rsyslog mailing list
> https://lists.adiscon.net/mailman/listinfo/rsyslog
> http://www.rsyslog.com/professional-services/
> What's up with rsyslog? Follow https://twitter.com/rgerhards
> NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad
> of sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you
> DON'T LIKE THAT.
>
_______________________________________________
rsyslog mailing list
https://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of 
sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE 
THAT.

Reply via email to