I found that reload option is better than restart httpd service. systemctl restart httpd
Answer from Savana Rohit on Stack OverflowVideos
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:
This is equivalent to apachectl -k graceful.
On my Centos6 box, I had been using the command service httpd graceful.
That no longer worked on Centos7. It's necessary to use apachectl graceful to do the equivalent on Centos 7. Also apachectl graceful works just fine on Centos 6.
Most systemd-based distributions use a patched apachectl script [1] that delegates commands to systemctl. The patched apachectl command does not support the "pass-through" mode of operation in which arguments are passed through to httpd. The apachectl manual page reflects the upstream non-patched apachectl 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:
sudo systemctl reload httpd.service
Under the hood, this invokes httpd -k graceful. You can verify this with this command:
$ systemctl cat httpd.service | grep -F ExecReload
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
To stop the Apache HTTP Server:
sudo systemctl stop httpd.service
which, behind the scenes, sends a SIGWINCH signal to the httpd process.
This can be verified with this command:
$ systemctl cat httpd.service \
| grep -E --before-context=1 'ExecStop|KillSignal'
# Send SIGWINCH for graceful stop
KillSignal=SIGWINCH
The systemd.service [3] manual says that in this situation, where the ExecStop option is not specified, "the process is terminated by sending the signal specified in KillSignal."
Why SIGWINCH? Because, per https://bz.apache.org/bugzilla/show_bug.cgi?id=50669 , Apache uses the SIGWINCH 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:
$ systemctl show httpd.service -p ExecStart -p ExecReload -p ExecStop -p KillSignal
[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
you are doing it right. It sends your command to httpd service. You can use this command to see status of last command sent:
service httpd status
Welcome to Systemd! This has replaced service in recent Red Hat ilk, such as CentOS 7. You are on the right track with systemctl. Now, instead of checking logs in /var/log/messages/, you use journalctl to view logs. To look at logs specific to “httpd”, you can look at the “unit” with:
journalctl -u httpd
Other useful things to do with journalctl:
alias jc='journalctl -xa' # make a friendly alias for ease of typing
jc -f # follow the current events
The localhost fix should have ideally solved the problem. Just make sure that where you added the localhost in front of ServerName, that line is not commented.
Also make sure there are no duplicate files of the httpd.conf file. I had the same problem once and when I googled, I found that -
/etc/httpd/conf/httpd.conf and /etc/httpd/conf.d/system-config-httpd.conf
deleting the second one, fixed the issue for me.
If that is not the case, I hope you have already tried this -
instead of direct restart, do
/sbin/service httpd stop
/sbin/service httpd start
If that doesn't work, try
apachectl restart
or
apache2ctl restart
This ideally shouldn't make a difference, it executes the same command, but worth a try.
from your logs it looks like you have two problems:
- "Address already in use" error - it seems you have twice specified "Listen" parameter in the apache configuration files.
- Unable to open logs - check that apache have rw permissions to log files.
You could run your script via a cronjob.
For this, add this to your crontab-file:
59 23 * * * /bin/systemctl restart httpd.service
This will execute /bin/systemctl restart httpd.service one time at 23:59 every day of every week of every month.
Even though the cron solution is certainly the best option, you can also use some Systemd directives to get almost the same result.
As root, create the /etc/systemd/system/httpd.service.d directory:
mkdir /etc/systemd/system/httpd.service.d
cd /etc/systemd/system/httpd.service.d
Create the restart.conf file and paste the following lines into it:
[Service]
WatchdogSec=1day
Restart=always
You now need to restart the global daemon configuration:
systemctl daemon-reload
Finally, you have to restart the httpd service:
systemctl restart httpd
Every day the watchdog timer will interrupt the httpd daemon and Systemd will restart it just after.