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
What is yum-cron ?
Viewed 3184 times since Fri, Oct 26, 2018
RHEL: iSCSI target/initiator configuration on RHEL7
Viewed 11971 times since Sat, Jun 2, 2018
List of 10 Must Know Oracle Database Parameters for Database Administrator
Viewed 133100 times since Thu, Jun 21, 2018
How To Use the Linux Auditing System on CentOS 7
Viewed 4542 times since Fri, Apr 5, 2019
How to convert RAW image to VDI and otherwise
Viewed 15663 times since Wed, Oct 3, 2018
RHEL: Checking HBAs
Viewed 15702 times since Sun, May 27, 2018
Linux How to reset a root password on Fedora
Viewed 3105 times since Sun, Dec 6, 2020
RHEL: Forgotten ’root’ password / using single-user to gain access
Viewed 8355 times since Sat, Jun 2, 2018
How to Clear RAM Memory Cache, Buffer and Swap Space on Linux
Viewed 3514 times since Mon, Nov 23, 2020
haproxy linux
Viewed 3009 times since Sun, Dec 6, 2020