My system is centos 7.4, with apache 2.4
Based on apache manual,apachectl -k graceful
should be the way to graceful restart apache, but I got notice as below:
[root@localhost root]# apachectl -k graceful
Passing arguments to httpd using apachectl is no longer supported.
You can only start/stop/restart httpd using this script.
If you want to pass extra arguments to httpd, edit the
/etc/sysconfig/httpd config file.
What's the problem?
How to Graceful Restart Apache
in centos 7?
Please see this page on apachectl, which appears to be a new version: https://httpd.apache.org/docs/2.4/programs/apachectl.html
There is no need to pass the '-k' argument.
apachectl graceful
(without the -k) works just fine for a graceful reload/restart on my Centos7 box and Centos6 box.Apparently nobody updated the manual page OP cited in her question, which still exists, and where the commands are shown with the '-k' argument throughout (apachectl -k graceful, apachectl -k restart, etc.) There's no explanation on that page about what the -k argument is actually doing, however.
But on the newer page there is this note on about apachectl graceful:
On my Centos6 box, I had been using the command
service httpd graceful
. That no longer worked on Centos7. It's necessary to useapachectl graceful
to do the equivalent on Centos 7. Alsoapachectl graceful
works just fine on Centos 6.Most systemd-based distributions use a patched
apachectl
script [1] that delegates commands tosystemctl
. The patchedapachectl
command does not support the "pass-through" mode of operation in which arguments are passed through tohttpd
. The apachectl manual page reflects the upstream non-patchedapachectl
command, hence the discrepancy.I recommend using the
systemctl
[2] abstraction for starting and stopping services.Thus, to gracefully restart the Apache HTTP Server on Centos 7, and other linux distributions using systemd, use:
Under the hood, this invokes
httpd -k graceful
. You can verify this with this command:To stop the Apache HTTP Server:
which, behind the scenes, sends a
SIGWINCH
signal to thehttpd
process.This can be verified with this command:
The
systemd.service
[3] manual says that in this situation, where theExecStop
option is not specified, "the process is terminated by sending the signal specified inKillSignal
."Why
SIGWINCH
? Because, per https://bz.apache.org/bugzilla/show_bug.cgi?id=50669 , Apache uses theSIGWINCH
signal as a 'graceful shutdown' trigger.Another command you may find useful to explore service options is the
show
command combined with-p, --property
options, like this:[1] https://git.centos.org/blob/rpms!httpd.git/c7/SOURCES!httpd-2.4.3-apctl-systemd.patch
[2] https://www.freedesktop.org/software/systemd/man/systemctl.html
[3] https://www.freedesktop.org/software/systemd/man/systemd.service.html
As with other Linux distributions that use systemd, you can manage httpd with
systemctl
. In particular:will cause httpd to reload its configuration files and restart its workers with the new configuration, exactly as
graceful
did.