Personal tools
You are here: Home Leocornus Leocornus Buildout Config Repository. Configuration and setup for logrotate

Configuration and setup for logrotate

logrotate to rotate and housekeeping all kind of log files. including the following popular applications:

  • Nginx
  • Tomcat
  • MariaDB

logrotate basic

The basic logrotate configruation file:

rotate 5
daily
create
compress
delaycompress

# logrotate conf file for Nginx log files
${:nginx-log-files}

Nginx logrotate config

Here is a sample for Nginx logrotate config:

# this is like a sample file:
${settings:log-directory}/frontend*.log {
    sharedscripts
    postrotate
        /bin/kill -USR1 $(cat ${settings:log-directory}/frontend.pid)
    endscript
}

The kill signal USR1 is for Reopen log files. The details list of Nginx server signals could be find in Nginx Command Line wiki page.

Tomcat logrotate config

Tomcat's logging system is based on Log4j / Java Logging API. It could be configurated to rotate logging file every day. But it will NOT do the housekeeping working for all those log files.

The choice here is turn off the rotation for tomcat logging settings, and use the logrotate to rotate and housekeeping log files.

Steps need to be done:

  • using jsvc to run tomcat as a daemon on Unix.
  • config tomcat logging to turn off logging rotating, 2 files: logging.properties and server.xml
  • logrotat configuration, using jsvc kill signal SIGUSR1 to reopen log files.

Here is a sample logrotate configuration file for tomcat on jsvc:

/path/to/tomcat/catalina/log.files {
    postscript
        /bin/kill -SIGUSR1 /path/to/jsvc.pid
    endscript
}
Document Actions