sudo service apache2 restart for the way that's borrowed from Red Hat.
sudo service apache2 restart for the way that's borrowed from Red Hat.
Do you want to restart Apache, or do you want to gracefully reload its configuration?
Everyone was answering the first question; you can do the second with
sudo service apache2 reload
Gracefully reloading is a bit faster, and there's no downtime.
There's one caveat: if your apache config files contain an error (e.g. configures a log file in a directory that doesn't exist), the server may silently exit without printing any error messages to the console. Most other errors are caught by the apache2ctl configtest that service apache2 reload runs before doing the actual reload with apache2ctl graceful.
Videos
I had a similar problem, and for me it was about the logged in user not having privileges so instead of
service apache2 restart
I had to do
sudo service apache2 restart
It's telling you some other service is already on port 80, perhaps it's apache
try Code:
sudo /etc/init.d/apache2 stop
followed by Code:
sudo killall apache2
then make sure no services are running on port 80 Code:
sudo netstat -l|grep www
then (re)start apache Code:
sudo /etc/init.d/apache2 restart
If you use apache as the primary service to keep your running container, you can NOT reboot it. Simply because you built the image and sets the CMD with it.
The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.
Try to reload without restart a service:
/etc/init.d/apache2 reload
My solution to this was to exit my bash shell into the container, and just restart the container outside of Docker. Because Apache is set as the primary service, this also restarts Apache, and doesn't crash the container.
docker restart <container>
Some other process is already using port 80. To find out what process it is do a
netstat -tulpen | grep 80
In the right column of the output you will see the name and id of the process blocking the port. In order to be able to start the apache2 service you have to stop (or kill) it.
# /etc/init.d/apache2 restart
OR $ sudo /etc/init.d/apache2 restart
OR $ sudo service apache2 restart
There is already a process listening on Port 80.
You can identify it by running the following command:
sudo netstat -anp | grep "0.0.0.0:80"
The rightmost column will give you the PID of the offending process(es).
If you are certain your Apache instance is the only thing that should be bound to port 80 on this system and running the init 'stop' script has had no effect, you can attempt to kill INSERTPIDHERE them and then try to start Apache again.
Your best bet is that part or all of the earlier HTTPD server is still running, whether active or hung. I would suggest that you:
sudo /etc/init.d/apache2 stop && ps -leaf | egrep -i "(http|apache)"
Anything printed by the grep is a likely suspect. If nothing is printed you should check for other processes listening, or otherwise using, port 80.
In typical operation (running as a service, not troubleshooting or debugging, etc), the "proper" way to do it is with the service command:
service apache2 start
service apache2 stop
service apache2 restart
service apache2 reload (when you want to reload the config)
The directory that this is run from is inconsequential. And for your information, the scripts that the service command uses are in /etc/init.d; Apache's resides at /etc/init.d/apache2. So /etc/init.d/apache2 start etc. will also get what you want; but Ubuntu 10.10 and newer will whine at you to use the service command instead.
You could also use:
invoke-rc.d apache2 start
This should also allow you to run the Apache 2 init.d script.