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
Secure Secure Shell
Viewed 10124 times since Fri, Aug 21, 2020
How to run command or code in parallel in bash shell under Linux or Unix
Viewed 2776 times since Tue, Aug 6, 2019
Linux How to reset a root password on Fedora
Viewed 1972 times since Sun, Dec 6, 2020
ZPOOL: Detach a submirror from a mirrored zpool
Viewed 2311 times since Sun, Jun 3, 2018
Installing and Configuring stunnel on CentOS 6
Viewed 3803 times since Fri, Sep 28, 2018
Transform XML to CSV Format | Unix String Pattern Manipulation The Ugly Way
Viewed 4633 times since Sun, Jan 9, 2022
Linux - How to get IP and MAC address of ethernet adapter in Linux
Viewed 2376 times since Fri, Jun 8, 2018
Linux Network (TCP) Performance Tuning with Sysctl
Viewed 10820 times since Fri, Aug 3, 2018
RHEL: Allowing users to ’su’ to "root" / Allowing ’root’ to login directly to the system using ’ssh’
Viewed 2502 times since Sat, Jun 2, 2018
Linux - How to unlock and reset user’s account
Viewed 3728 times since Fri, Jun 8, 2018