10

Is it safe to perform a graceful restart of Apache on a production server? What effects will a graceful restart cause and what would be the impact (if any)? Will there be any detrimental impacts (e.g. downtime, even if it is for a short time)?

I have considered the following resources, but it is still unclear what the impacts on users will be:

stellarchariot
  • 209
  • 1
  • 2
  • 5

3 Answers3

9

When performing a graceful restart, existing connections should run to normal completion at which point their workers will terminate. New workers should already be started to handle new connections.

You shouldn't notice any connection failures or slow page loads but in practice you may see new connections queue briefly while the config is re-loaded by the master thread (mine takes under half a second)

If you are restarting to pick up a new config then there is a risk there may be a config error which could prevent the server restarting properly.

If the server is in an abnormal state it may fail to restart gracefully (perhaps thats why you are considering a graceful restart)

Tricky
  • 376
  • 2
  • 5
1

If Apache is serving static files, and isn't acting as the front to something like , it's pretty smooth. Most users won't even notice, and those that do will consider it normal glitchiness. Apache won't serve new requests until the old ones are served, so you'll be waiting until they all finish up. If someone is downloading a 500MB file at 68KB/s you may be waiting a LONG TIME, during which no other serving is happening.

If Apache is fronting an application server, the situation can be very different. From experience, the UX for interacting with that server will be very bad until the app server is up, loaded, and the caches are warmed.

sysadmin1138
  • 131,083
  • 18
  • 173
  • 296
  • 5
    Also, it is VERY important to do a `/etc/init.d/httpd configtest` before proceeding with any kind of apache restarts on a production server. – Sreeraj Dec 02 '14 at 12:26
  • Indeed — it is quite important to run a configtest. IIRC, I think with later versions of Apache might perform an implicit configtest before a graceful restart, and if it fails the configtest, it won't continue with the restart. – stellarchariot Dec 03 '14 at 02:49
  • 5
    " Apache won't serve new requests until the old ones are served, so you'll be waiting until they all finish up. If someone is downloading a 500MB file at 68KB/s you may be waiting a LONG TIME, during which no other serving is happening." This is not accurate. The configuration is reloaded immediately and new child processes are created, accept connections, and process requests while the previous generation are finishing their last requests. – covener Dec 03 '14 at 03:25
0

The aforementioned graceful parameter tells httpd to begin the restarting process by first signaling all of its child processes to complete their current tasks. After all the child processes (the ones that are serving up http requests) have finished their tasks, they will close; if any child processes aren’t currently serving requests, they will close immediately.

Whereas, stop attempts to terminate all child processes immediately, which could leave end-users hanging. My preference is graceful — a better choice for your business-class server — because it’s friendlier than abruptly terminating child processes that are serving customers. Many admins and especially programmers use stop to stop their server, often because they don’t know that graceful even exists.

Link: https://www.godaddy.com/garage/tech/config/how-to-restart-apache-without-rebooting-your-centos-linux-server/ Link

Somdip Dey
  • 101
  • 2