Linux LogRotate Task Failed

I have completed the log rotate task as per requirement. In question it was asked to set log rotation for monthly basis and rotate count to 3 and even after that my task got failed. Attaching the screenshot for ref.

Hi  @jadhav.darshan2015 
You  set log rotation correctly: Ok

But you didn't check if  the haproxy.log exists.

If you check  , you will find that there's no haproxy.log  in /var/log:

ls -l /var/log/haproxy.log

ls: cannot access /var/log/haproxy.log: No such file or directory


###  by default  there's  no haproxy.log  in /var/log
# to have these messages end up in /var/log/haproxy.log you will
# need to configure  /etc/sysconfig/rsyslog  and   /etc/rsyslog.conf

edit  /etc/sysconfig/rsyslog:
----------------------------

vi /etc/sysconfig/rsyslog
 
    #   configure rsyslog to accept network log events.  This is done
    #    add  '-r' option to the SYSLOGD_OPTIONS  
 

 save  &  exit
 
 edit  /etc/rsyslog.conf:
----------------------------
vi  /etc/rsyslog.conf

    # 1) configure local2 events to go to the /var/log/haproxy.log file
    #  Add  the following line at the end of /etc/rsyslog.conf:
    #    local2.*                       /var/log/haproxy.log

   # 2) uncomment the  following lines(s) preceded  by the line " # Provides UDP syslog reception":   
   #$ModLoad imudp                                                                                                                                       
   #$UDPServerRun 514     

save &  exit

restart  rsyslog:
----------------
systemctl  restart  rsyslog

Restart  haproxy  service:
------------------------

systemctl  restart   haproxy

check  haproxy.log:
-------------------

ls -l /var/log/haproxy.log

-rw-------. 1 root root 1553 Jul 31 18:02 /var/log/haproxy.log


execute logrotate  for  haproxy  with (-v)  option:
-----------------------------------------------
 
logrotate -v  /etc/logrotate.d/haproxy 

Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /var/log/haproxy.log  monthly (3 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/haproxy.log
  log does not need rotating (log has been rotated at 2021-7-31 17:0, that is not month ago yet)
not running postrotate script, since no logs were rotated
set default create context

Good Luck !

1 Like