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
Using IOzone for Linux disk performance analysis
Viewed 9555 times since Wed, Jul 25, 2018
RHCS6: Reduce a Global Filesystem 2 (GFS2)
Viewed 4210 times since Sun, Jun 3, 2018
RHEL: Services basic management - systemd
Viewed 20172 times since Sat, Jun 2, 2018
RHEL : How to deal with “CLOSE_WAIT” and “TIME_WAIT” connection
Viewed 30045 times since Thu, Feb 14, 2019
Linux Network (TCP) Performance Tuning with Sysctl
Viewed 13456 times since Fri, Aug 3, 2018
Linux RedHat How To Create An RPM Package
Viewed 4315 times since Sun, Jan 9, 2022
Manage Linux Password Expiration and Aging Using chage
Viewed 6308 times since Tue, Sep 11, 2018
Jak ustawić LVM, jak robić snapshoty oraz automatycznie powiększać LV, czyli małe howto
Viewed 5731 times since Sun, May 20, 2018
Using etckeeper with git
Viewed 8294 times since Sun, Jun 3, 2018
RHEL: Reserved space on a ext2/ext3/ext4 filesystem
Viewed 5679 times since Sun, May 27, 2018