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
Jak ustawić LVM, jak robić snapshoty oraz automatycznie powiększać LV, czyli małe howto
Viewed 1813 times since Sun, May 20, 2018
RHEL: Displaying system info (firmware, serial numbers... )
Viewed 1466 times since Sun, May 27, 2018
Install OpenVPN On CentOS / RHEL 7
Viewed 336 times since Fri, May 15, 2020
Procedura powiekszania OCFS2 online
Viewed 618 times since Fri, Jun 8, 2018
debian How to check Debian CVE status using python script
Viewed 553 times since Sun, Sep 23, 2018
Linux – How to check the exit status of several piped commands
Viewed 1501 times since Wed, Jul 25, 2018
watchdog How to restart a process out of crontab on a Linux/Unix
Viewed 1997 times since Tue, Jul 31, 2018
Using IOzone for Linux disk performance analysis
Viewed 3156 times since Wed, Jul 25, 2018
Red Hat Cluster Tutorial
Viewed 822 times since Sun, Jun 3, 2018
OEL 7 – How to disable IPv6 on Oracle Linux 7 – Follow Up
Viewed 821 times since Wed, Jul 25, 2018