Urban legends: Apache reload(ed)

What's the difference between reloading and restarting an Apache web server? If you google for this you'll find a lot of (wrong) information which may sum up like this:

A reload just let Apache re-read it's configuration file, without restarting the Apache. But if you need to do bigger changes to the config, like adding or removing modules or virtual hosts, you'll may need to do a real restart.

Something like this.

If Penn & Teller would care about Apache configuration, they would agree: This is bullshit!

Apache never supported something like a reload mechanism. And therefore there is no such functionality. If you accept this fact, you're a step closer to the truth.

Origins

One origin of this legend is probably to be found in the fact that classic Unix daemons have a "reload" mechanism which is triggered by sending an HUP (hang up) signal to the process. A process getting such a HUP signal didn't hang up but reloaded its own configuration file. Without the need of restarting. Later this functionality was made available by the System V init scripts, which are still the most common and popular way of controlling Unix services. That's what we use if we call some script within /etc/init.d, /etc/rc.d, etc.

Most of this scripts are enabling the user (aka root) to start, stop, reload a specific service (aka daemon). And for example if you look into /etc/init.d/crond on a RHEL 5.2 you can track down the reload to a single HUP signal:

echo -n $"Reloading cron daemon configuration: "
killproc crond -HUP

And as for every other system daemon also Apache's init scripts offer the user to reload the Apache web server. An example from Debian 5.0:

# /etc/init.d/apache2 
Usage: /etc/init.d/apache2 {start|stop|restart|reload|...}.

BTW: On OpenSolaris it's called refresh instead of reload. But that's just another wording.

The Truth

If you track down this reload functionality you'll find something like this:

On Debian's /etc/init.d/apache2:

log_daemon_msg "Reloading web server config" "apache2"
$APACHE2CTL graceful $2

Or on OpenSolaris /lib/svc/method/http-apache22:

cmd="graceful"
${APACHE_BIN}/apachectl ${STARTUP_OPTIONS} ${cmd}

So if you track down the "reload" you end up with a "graceful". And now we're at the beginning of this blog entry: Apache never supported something like a reload mechanism. And therefore there is no such functionality.

And "graceful" means according to the Apache HTTP Server 2.2 Documentation:

Graceful Restart: 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.

So the "reload" ends up in a restart of all the Apache children and from a internal configuration-releated view, a graceful restart is exactly the same as a regular restart. It's just better for the stability of your web site, because the children are ended after finishing their current HTTP request and not terminated while serving a client.

The Conclusion

If you change you Apache's configuration do a "reload" or whatever your system calls it. There is no need for a regular restart. But you may need to wait some seconds until all the tiny Apache children processes catched up with the new configuration.

Postscript

On my RHEL 5.2 an Apache "reload" actually ends in an HUP signal:

echo -n $"Reloading $prog: "
killproc $httpd -HUP
Which would be right for a usual Unix daemon like crond but in case of Apache this means a restart and not a graceful restart. A graceful restart is triggered by an USR1 signal. Looks like a copy and paste error in RHEL 5.2. Probably this is fixed in newer releases.
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Kai 'Oswald' Seidler writes about his life as co-founder of Apache Friends, creator of XAMPP, and technology evangelist for web tier products at Sun Microsystems.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today