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
OpenSSL: Find Out SSL Key Length – Linux Command Line
Viewed 7140 times since Mon, Feb 18, 2019
systemd Auto-restart a crashed service in systemd
Viewed 3318 times since Fri, Jan 17, 2020
30 Handy Bash Shell Aliases For Linux / Unix / MacOS
Viewed 4907 times since Thu, Feb 11, 2021
RHEL: Route network packets to go out via the same interface they came in
Viewed 3185 times since Sat, Jun 2, 2018
Df command in Linux not updating actual diskspace, wrong data
Viewed 2974 times since Wed, May 30, 2018
stunnel bacula
Viewed 2140 times since Fri, Sep 28, 2018
12 Tcpdump Commands – A Network Sniffer Tool
Viewed 8854 times since Fri, Jul 27, 2018
Linux RedHat How To Create An RPM Package
Viewed 3333 times since Sun, Jan 9, 2022
BIND for the Small LAN
Viewed 3496 times since Sun, May 20, 2018
Securing /tmp and shm partitions
Viewed 3324 times since Fri, May 15, 2020