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
RHEL: Reserved space on a ext2/ext3/ext4 filesystem
Viewed 5506 times since Sun, May 27, 2018
Tcpdump Examples Linux
Viewed 6880 times since Fri, Nov 16, 2018
18 Quick ‘lsof’ command examples for Linux Geeks
Viewed 12922 times since Sun, Jun 30, 2019
How To Ping Specific Port Number
Viewed 6163 times since Mon, Jun 1, 2020
Top 25 Best Linux Performance Monitoring and Debugging Tools
Viewed 8088 times since Sun, Sep 30, 2018
How to maximise SSD performance with Linux
Viewed 9737 times since Fri, May 15, 2020
Installing and Configuring an OCFS2 Clustered File System
Viewed 6869 times since Sat, Jun 2, 2018
RHEL: Displaying/setting kernel parameters - ’sysctl’
Viewed 4017 times since Sat, Jun 2, 2018
YUM CRON RHEL7: Configure automatic updates.
Viewed 2602 times since Fri, Oct 26, 2018
OpenSSL: Check If Private Key Matches SSL Certificate & CSR
Viewed 3996 times since Mon, Feb 18, 2019