25

Is there a way to stop the Apache server without terminating executing requests, basically a way to tell it - don't accept any more connections and shut down when you finish your current ones?

3 Answers 3

38

Yes.

apachectl -k graceful-stop

https://httpd.apache.org/docs/2.4/stopping.html

2
  • Why the -k? I cannot find any documentation for that flag. Apr 8, 2022 at 8:06
  • -k: This is an option used to send signals to the Apache processes. Feb 27 at 14:30
12

Use apachectl -k graceful-stop from here:

The WINCH or graceful-stop 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 will then remove its PidFile and cease listening on all ports. The parent will continue to run, and monitor children which are handling requests. Once all children have finalised and exited or the timeout specified by the GracefulShutdownTimeout has been reached, the parent will also exit.

1

Keep in mind that sys-v init used to do graceful stop by default and had force-stop as an extra option. A “special” option to gracefully stop is only needed if you run a custom process manager that normally kills processes.

4
  • This answer could give the impression that because systemd isn't a custom process manager it doesn't kill the process. However, by default systemd also performs a stop not a graceful-stop for apache.
    – B. Miller
    May 29, 2018 at 18:53
  • 4
    @B.Miller if your systemd performs a stop instead of a graceful-stop, that's an OS-specific bug that needs to be logged. Arch Linux and CentOS 7 both perform graceful stops.
    – Harald
    May 29, 2018 at 19:41
  • Debian does a graceful stop too May 29, 2018 at 19:45
  • 2
    Interesting @JohnKeates ... maybe this is Ubuntu 18.04 specific. 18.04 uses the stop command /usr/sbin/apachectl stop
    – B. Miller
    May 29, 2018 at 20:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .