Some day as system engineer i face the trouble, log rotate config on for cleaning catalina.out file was stuck, so i try to run it manually. we also can run manually for testing the log rotate configuration was running well or not
than we have to wait for the running schedule automatically.
If you want to force-run a single specific directory or daemon's log files, you can usually find the configuration in
/etc/logrotate.d
, and they will work standalone.
Keep in mind that global configuration specified in /etc/logrotate.conf
will not apply, so if you do this you should ensure you specify all the options you want in the /etc/logrotate.d/[servicename]
config file specifically.
You can try it out with -d
to see what would happen:
logrotate -df /etc/logrotate.d/catalina
The file of catalina.out file before execute the log rotate
[maswachid@tomcat logs]$ ls
catalina.2018-05-06.log localhost_access_log.2018-05-22.txt localhost_access_log.2018-06-20.txt
catalina.2018-05-07.log localhost_access_log.2018-05-23.txt localhost_access_log.2018-06-21.txt
catalina.2018-05-29.log localhost_access_log.2018-05-24.txt localhost_access_log.2018-06-22.txt
catalina.2018-06-22.log localhost_access_log.2018-05-25.txt localhost_access_log.2018-06-23.txt
catalina.2018-06-27.log localhost_access_log.2018-05-26.txt localhost_access_log.2018-06-24.txt
catalina.out localhost_access_log.2018-05-27.txt localhost_access_log.2018-06-25.txt
host-manager.2018-05-06.log localhost_access_log.2018-05-28.txt localhost_access_log.2018-06-26.txt
host-manager.2018-05-07.log localhost_access_log.2018-05-29.txt localhost_access_log.2018-06-27.txt
host-manager.2018-05-29.log localhost_access_log.2018-05-30.txt localhost_access_log.2018-06-28.txt
when the command execute, here are the output
[maswachid@tomcat logrotate.d]$ logrotate -df /etc/logrotate.d/catalinaout_sch
reading config file /etc/logrotate.d/catalinaout_sch
Allocating hash table for state file, size 15360 B
Handling 1 logs
rotating pattern: /opt/tomcatstack-7.0_scheduler/apache-tomcat/logs/catalina.out forced from command line (7 rotations)
empty log files are rotated, old logs are removed
considering log /opt/tomcatstack-7.0_scheduler/apache-tomcat/logs/catalina.out
log needs rotating
rotating log /opt/tomcatstack-7.0_scheduler/apache-tomcat/logs/catalina.out, log->rotateCount is 7
dateext suffix '-20180811'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.7.gz to /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.8.gz (rotatecount 7, logstart 1, i 7),
renaming /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.6.gz to /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.7.gz (rotatecount 7, logstart 1, i 6),
renaming /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.5.gz to /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.6.gz (rotatecount 7, logstart 1, i 5),
renaming /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.4.gz to /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.5.gz (rotatecount 7, logstart 1, i 4),
renaming /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.3.gz to /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.4.gz (rotatecount 7, logstart 1, i 3),
renaming /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.2.gz to /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.3.gz (rotatecount 7, logstart 1, i 2),
renaming /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.1.gz to /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.2.gz (rotatecount 7, logstart 1, i 1),
renaming /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.0.gz to /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.1.gz (rotatecount 7, logstart 1, i 0),
copying /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out to /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.1
truncating /opt/tomcatstack-7.0_scheduler/apache-tomcat/logs/catalina.out
compressing log with: /bin/gzip
removing old log /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.8.gz
error: error opening /opt/tomcatstack-7.0/apache-tomcat/logs/catalina.out.8.gz: No such file or directory
[maswachid@tomcat logrotate.d]$
Then you can run (using catalina as an example):
logrotate -f /etc/logrotate.d/catalina
Execute log rotate single config manually and the result as shown bellow
[maswachid@tomcat logrotate.d]$
[maswachid@tomcat logrotate.d]$ sudo logrotate -f /etc/logrotate.d/catalinaout_sch
[maswachid@tomcat logrotate.d]$
[maswachid@tomcat logrotate.d]$ ls /opt/tomcatstack-7.0/apache-tomcat/logs/
catalina.2018-05-06.log localhost_access_log.2018-05-21.txt localhost_access_log.2018-06-19.txt
catalina.2018-05-07.log localhost_access_log.2018-05-22.txt localhost_access_log.2018-06-20.txt
catalina.2018-05-29.log localhost_access_log.2018-05-23.txt localhost_access_log.2018-06-21.txt
catalina.2018-06-22.log localhost_access_log.2018-05-24.txt localhost_access_log.2018-06-22.txt
catalina.2018-06-27.log localhost_access_log.2018-05-25.txt localhost_access_log.2018-06-23.txt
catalina.out localhost_access_log.2018-05-26.txt localhost_access_log.2018-06-24.txt
catalina.out.1.gz localhost_access_log.2018-05-27.txt localhost_access_log.2018-06-25.txt
host-manager.2018-05-06.log localhost_access_log.2018-05-28.txt localhost_access_log.2018-06-26.txt
host-manager.2018-05-07.log localhost_access_log.2018-05-29.txt localhost_access_log.2018-06-27.txt
host-manager.2018-05-29.log localhost_access_log.2018-05-30.txt localhost_access_log.2018-06-28.txt
localhost.2018-05-06.log localhost_access_log.2018-05-31.txt localhost_access_log.2018-06-29.txt
And the catalina logs alone will be rotated.
Tidak ada komentar :
Posting Komentar