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 /dev/shm And Its Practical Usage
Viewed 8224 times since Tue, Mar 12, 2019
Linux - How to perform I/O performance test with dd command
Viewed 6199 times since Fri, Jun 8, 2018
RHCS6: ’fencing’ basics
Viewed 2396 times since Sun, Jun 3, 2018
Jak ustawić LVM, jak robić snapshoty oraz automatycznie powiększać LV, czyli małe howto
Viewed 4803 times since Sun, May 20, 2018
HowTo: The Ultimate Logrotate Command Tutorial with 10 Examples
Viewed 5516 times since Fri, Nov 30, 2018
Szybkie sprawdzenie zewnętrznego adresu IP i hosta
Viewed 3512 times since Thu, May 24, 2018
Easily Find Bugs In Shell Scripts With ShellCheck
Viewed 3450 times since Thu, Apr 18, 2019
RHCS6: Luci - the cluster management console
Viewed 3352 times since Sun, Jun 3, 2018
Cron YUM How to use yum-cron to automatically update RHEL/CentOS Linux
Viewed 2624 times since Fri, Oct 26, 2018
Top 20 OpenSSH Server Best Security Practices ssh linux aix
Viewed 6138 times since Fri, May 15, 2020