2

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

Ralph
  • 105
  • 1
  • 6

2 Answers2

4

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

idleyoungman
  • 320
  • 1
  • 7
0

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."

desasteralex
  • 968
  • 4
  • 5
  • Thanks for your detailed reply. When I look at the server-status page, however, the Server Uptime usually resets after 7 days. Is this normal behavior then? I just want to make sure my Apache isn't restarting more than necessary. – Ralph Apr 24 '11 at 04:19
  • 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? – desasteralex Apr 24 '11 at 05:21
  • 1
    -1 See the answer by idleyoungman. From the [documentation](http://httpd.apache.org/docs/current/stopping.html#hup), 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." – Andomar Nov 14 '15 at 11:05