Change logrotate to reload Apache instead of restart

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,577
This is on CentOS 7. I have set /etc/logrotate.conf to rotate log files "daily", this happens every night. But it causes a apache restart, wich I do not like. I would like Apache to reload instead of restart.

I struggle to find the information I need to make this change. I have been looking at /etc/logrotate.d/apache wich contain this:

Code:
/var/log/httpd/access_log /var/log/httpd/agent_log /var/log/httpd/error_log /var/log/httpd/referer_log /var/log/httpd/suexec_log /var/log/suphp.log /var/log/httpd/sulsphp_log {
    missingok
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

I am considering changing this line:
Code:
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true

with this line:
Code:
/bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true

Is that the correct way to change it so that Apache is not restarted every night by logrotate but instead reloaded? Hopefully someone have experience changing this and can provide information about the correct way of changing this.
 
Hello,

Looks fine. You can check /etc/logrotate.d/named to be more sure:

Code:
/var/named/data/named.run {
    missingok
    su named named
    create 0644 named named
    postrotate
        /usr/bin/systemctl reload named.service > /dev/null 2>&1 || true
        /usr/bin/systemctl reload named-chroot.service > /dev/null 2>&1 || true
        /usr/bin/systemctl reload named-sdb.service > /dev/null 2>&1 || true
        /usr/bin/systemctl reload named-sdb-chroot.service > /dev/null 2>&1 || true
        /usr/bin/systemctl reload named-pkcs11.service > /dev/null 2>&1 || true
    endscript
}
 
Back
Top