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
ZFS: Verify/change properties of a zfs filesystem
Viewed 2637 times since Sun, Jun 3, 2018
Red Hat Cluster Tutorial
Viewed 2082 times since Sun, Jun 3, 2018
debian Debian/Ubuntu Linux: Find If Installed APT Package Includes a Fix/Patch Via CVE Number
Viewed 9494 times since Sun, Sep 23, 2018
linux-training.be gives you books for free to study Linux
Viewed 4960 times since Sat, Jun 2, 2018
10 Linux nslookup Command Examples for DNS Lookup
Viewed 10263 times since Sun, Sep 30, 2018
Set Up SSH Tunneling on a Linux / Unix / BSD Server To Bypass NAT
Viewed 11332 times since Fri, May 15, 2020
Install OpenVPN On CentOS / RHEL 7
Viewed 3072 times since Fri, May 15, 2020
LVM: Extend an existing Volume Group by adding a new disk
Viewed 2101 times since Sat, Jun 2, 2018
Securing /tmp and shm partitions
Viewed 3267 times since Fri, May 15, 2020
Script to Offline and Remove A Disk In Linux
Viewed 1985 times since Mon, Jan 28, 2019