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
Open SSL Encrypt & Decrypt Files With Password Using OpenSSL
Viewed 696 times since Mon, Feb 18, 2019
Enabling or disabling a repository using Red Hat Subscription Management
Viewed 858 times since Mon, Oct 29, 2018
FIO (Flexible I/O) – a benchmark tool for any operating system
Viewed 545 times since Wed, Jul 25, 2018
Linux - Cannot login from remote console but can access via ssh
Viewed 539 times since Fri, Jun 8, 2018
debian How to Upgrade Debian 8 Jessie to Debian 9 Stretch
Viewed 624 times since Sun, Sep 23, 2018
Enabling automatic updates in Centos 7 and RHEL 7
Viewed 532 times since Wed, Oct 17, 2018
LVM: Extend an existing Logical Volume / Filesystem
Viewed 762 times since Sat, Jun 2, 2018
Super Grub2 Disk
Viewed 649 times since Wed, May 22, 2019
How To Add Swap Space on Ubuntu 16.04
Viewed 518 times since Fri, Jun 8, 2018
LVM: Mount LVM Partition(s) in Rescue Mode
Viewed 858 times since Sat, Jun 2, 2018