Logrotate is a Linux utility that helps you manage the size and number of log files that are generated by various processes on your system.

It can also compress, archive, and delete old log files automatically. Logrotate is useful for keeping your disk space under control and complying with data protection regulations such as GDPR.

To use Logrotate, you need to create a configuration file for each process that generates log files. The configuration file specifies the location of the log files, how often they should be rotated, how many copies should be kept, and what actions should be taken before or after rotation. You can also use wildcards to match multiple log files with the same pattern.

These configuration files can not be edited from RunCloud dashboard at present. You need to log into your server via SSH and make changes manually.

You can find your configuration files in /etc/logrotate.d/ directory, which is included in the main /etc/logrotate.conf file. For example, here is the default sample configuration file for nginx, which is located in /etc/logrotate.d/nginx-rc on your servers connected to RunCloud.

You can edit the above log file to change the log retention settings. For example, you can replace the monthly with either daily, weekly, or yearly to change the log-rotation duration.

Furthermore, you can change the rotate <count> to specify the number of rotations, after which the log file will be deleted. Here is a sample config:

/var/log/nginx-rc/*.log <path to other your log files>{
    weekly
    rotate 4
    compress
    delaycompress
    missingok
    notifempty
}

The above configuration file tells Logrotate to:

  • Rotate all log files in the /var/log/nginx-rc/ directory every week.
  • Delete files older than 4 weeks.
  • Compress the old log files with gzip.
  • Delay the compression until the next rotation cycle to avoid compressing the current log file.
  • Ignore any missing log files, and do not report any errors.
  • Do not rotate empty log files.
  • Create new log files with 0640 permission, owned by the www-data user and adm group.
  • Run a shared script after rotating all log files, which sends a USR1 signal to nginx to reopen the log files.

Logrotate runs automatically as a cron job, usually daily.

You can also run it manually with the logrotate command, followed by the name of the configuration file or directory. To run Logrotate manually with the logrotate command, you can use the following syntax:

logrotate [options] config_file_or_directory

For example, if you want to run logrotate on the /etc/logrotate.d directory, which contains the configuration files for various system logs, you can use this command:

logrotate /etc/logrotate.d

logrotate is a Linux utility that rotates log files according to specified rules.

After rotating logs, you can view the logrotate status file (/var/lib/logrotate/status). The status file shows the last time logrotate rotated logs for each service. You can use the command tail /var/lib/logrotate/status to display the last 10 lines of the file.

You can use this command to check if logrotate is working properly and when it last rotated logs for each service. You can also specify some options to modify the behavior of logrotate, such as -v for verbose output, -f for forcing the rotation even if not needed, or -d for debugging mode. For a full list of options, you can use the --help flag or consult the main page for logrotate.