Logrotate Example for Custom Logs

Logrotate Example for Custom Logs

You will need this if you are using custom location for log files.

Below is example for Nginx where log files are directly created in /var/www/example.com/logs

You can put following in /etc/logrotate.d/nginx

/var/www/example.com/logs/*.log {
        daily
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 0640 www-data adm
        sharedscripts
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi; \
        endscript
        postrotate
                [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
        endscript
}

Verify

Its always better to verify if logrotate script is correct.

Just run command

logrotate -d

It will produce debug output.

Restart/Force Update

Remember, logrotate is not service which can be restarted. In case you need your logrotate script to run immediately, use:

logrotate -f -v /etc/logrotate.d/nginx

Rotating log is very important. Otherwise some day your harddisk may get full and then mysql will be the first process which will refuse to start!

0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
HowTo: The Ultimate Logrotate Command Tutorial with 10 Examples
Viewed 5650 times since Fri, Nov 30, 2018
RHEL: Back-up/Replicate a partition table
Viewed 3728 times since Sun, May 27, 2018
SPRAWDZONA KONFIGURACJA RSYSLOG I LOGROTATE, JAKO ZEWNĘTRZNEGO SERWERA SYSLOG
Viewed 4033 times since Fri, Nov 30, 2018
RHEL: Create a local RPM repository
Viewed 11478 times since Sun, May 27, 2018
RHEL: Building a custom kernel on RHEL 6
Viewed 4367 times since Sat, Jun 2, 2018
IPTABLES linux
Viewed 17296 times since Sat, Jun 2, 2018
SSH Essentials: Working with SSH Servers, Clients, and Keys
Viewed 4748 times since Wed, Jun 27, 2018
Linux nslookup Command Examples for DNS Lookup
Viewed 9192 times since Sat, Sep 29, 2018
Check a Website Availability from the Linux Command Line
Viewed 6891 times since Mon, Feb 18, 2019
LVM: Rename root VG/LV
Viewed 7907 times since Sat, Jun 2, 2018