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
HP-UX - Stunnel Configuration
Viewed 3320 times since Fri, Sep 28, 2018
Set Up SSH Tunneling on a Linux / Unix / BSD Server To Bypass NAT
Viewed 12067 times since Fri, May 15, 2020
VMWare tools free
Viewed 10030 times since Mon, Jul 16, 2018
RHEL: Create a local RPM repository
Viewed 12271 times since Sun, May 27, 2018
Linux get the list of FC HBA’s and WWPN
Viewed 4400 times since Tue, May 22, 2018
RHEL: Allowing users to ’su’ to "root" / Allowing ’root’ to login directly to the system using ’ssh’
Viewed 3696 times since Sat, Jun 2, 2018
how to list all hard disks in linux from command line
Viewed 5112 times since Mon, Jan 28, 2019
Turbocharge PuTTY with 12 Powerful Add-Ons – Software for Geeks #3
Viewed 15764 times since Sun, Sep 30, 2018
Manage Linux Password Expiration and Aging Using chage
Viewed 5934 times since Tue, Sep 11, 2018
Using Kerberos security with Server for NFS
Viewed 11063 times since Wed, Jun 27, 2018