Logrotate configuration for httpd (CentOS)

6,173

Solution 1

No, the '/sbin/service httpd reload' command does not kill all connections as it does not initiate a 'hard restart'. CentOS triggers Apache via service, other OSs do via init scripts. For all of them a 'reload' means a graceful restart/sending Apache the USR1 signal:

"The USR1 or graceful signal causes the parent process to advise the children to exit after their current request (or to exit immediately if they're not serving anything). The parent re-reads its configuration files and re-opens its log files. As each child dies off the parent replaces it with a child from the new generation of the configuration, which begins serving new requests immediately."

Solution 2

The original answer is not correct. The initscript "reload" just passes the reload command to apachectl. A reload sends SIGHUP to httpd, which immediately terminates the child processes and does interrupt currently connected clients: http://httpd.apache.org/docs/current/stopping.html#hup

See a bug filed against the RHEL httpd package: https://bugzilla.redhat.com/show_bug.cgi?id=480624

The reason graceful is not used in the logrotate script is because there's no way to guarantee the the child processes have stopped: http://httpd.apache.org/docs/current/stopping.html#graceful

Share:
6,173

Related videos on Youtube

Ralph
Author by

Ralph

Updated on September 18, 2022

Comments

  • Ralph
    Ralph almost 2 years

    I'm running Apache 2.2.3 on CentOS 5.5 and just noticed the following logrotate postrotate configuration in /etc/logrotate.d/httpd:

    postrotate
    /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
    

    Since this is set to run once per week, it does a hard reload for Apache, which seemingly kills all connections (is this right? I'm not an expert). Would it be safer to change the postrotate script to a graceful restart instead?

    /usr/sbin/apachectl graceful > /dev/null
    

    This is the postrotate behavior I already have for my virtual hosts. I don't understand why the httpd rotate scripts needs to do a hard reload.

    Any advice on how to configure this properly will be greatly appreciated.

    Thanks, Ralph

  • desasteralex
    desasteralex about 13 years
    Hmm, if the server uptime at the server-status page gets reset every 7 days, then your Apache seems to get indeed restarted regularly. Did you checked your /etc/crontab as well as the scripts in the /etc/cron.weekly/ folder?
  • Andomar
    Andomar over 8 years
    +1 Can confirm from testing that this is true
  • Andomar
    Andomar over 8 years
    -1 See the answer by idleyoungman. From the documentation, a reload "causes it to kill off its children like in TERM, but the parent doesn't exit. It re-reads its configuration files, and re-opens any log files."