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
Linux File Systems (mkfs, mount, fstab) ext4
Viewed 4295 times since Sat, Jun 2, 2018
Linux - How to get IP and MAC address of ethernet adapter in Linux
Viewed 3706 times since Fri, Jun 8, 2018
Linux Add a Swap File – HowTo
Viewed 11150 times since Fri, Jun 8, 2018
OEL 7 – How to disable IPv6 on Oracle Linux 7 – Follow Up
Viewed 10710 times since Wed, Jul 25, 2018
RHCS6: Quorum disk and heuristics
Viewed 5658 times since Sun, Jun 3, 2018
YUM CRON Enabling automatic updates in Centos 7 and RHEL 7
Viewed 13017 times since Fri, Oct 26, 2018
Understanding logrotate utility part 1
Viewed 2688 times since Fri, Nov 30, 2018
Applescript: Run or Call a Shell Script
Viewed 5493 times since Tue, Aug 6, 2019
WatchDog watchdog.sh script for checking server running
Viewed 6583 times since Tue, Jul 31, 2018
20 Linux YUM (Yellowdog Updater, Modified) Commands for Package Management YUM
Viewed 12311 times since Thu, Oct 25, 2018