Not able to stop apache processes

Update: Responding to the comment:

check processes of apache:

$ ps a | grep apache 3
grep: 3: No such file or directory
$ ps a | grep apache
 4514 pts/0    S+     0:00 grep --color=auto apache
$ ps a | grep apache2
 4516 pts/0    S+     0:00 grep --color=auto apache2

checking apache error log

$ tail /var/log/apache2/error.log
[Sun Aug 07 03:14:19 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.5 with Suhosin-Patch configured -- resuming normal operations
[Mon Aug 08 03:13:58 2011] [notice] Graceful restart requested, doing restart
[Mon Aug 08 03:14:00 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.5 with Suhosin-Patch configured -- resuming normal operations
[Mon Aug 08 09:03:16 2011] [notice] caught SIGTERM, shutting down
[Mon Aug 08 09:05:47 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.5 with Suhosin-Patch configured -- resuming normal operations

Original: I have stopped apache, but why it still has the same number of processes running?

$ ps -A | grep apache
 1663 ?        00:00:00 apache2
 1667 ?        00:00:00 apache2
 1668 ?        00:00:00 apache2
 1669 ?        00:00:00 apache2
 1670 ?        00:00:00 apache2
 1671 ?        00:00:00 apache2
$ /etc/init.d/apache2 stop
 * Stopping web server apache2                            [ OK ] 
$ ps -A | grep apache
 1663 ?        00:00:00 apache2
 1667 ?        00:00:00 apache2
 1668 ?        00:00:00 apache2
 1669 ?        00:00:00 apache2
 1670 ?        00:00:00 apache2
 1671 ?        00:00:00 apache2

Thanks!


Solution 1:

This can happen occasionally when Apache refuses to stop nicely or has Zombie Processes. For the former you can kill all running processes with sudo killall -9 apache2; however, for the latter you'll simple need to wait for them to go away. In the event it's Apache not wanting to stop nicely, what you'll really want to do is investigate what's going on. Finding out exactly what's going on can be difficult though.

An interactive strace of the process id may lend a clue as to what site(s) are acting up and causing issues. From your above ps -A you can check the first process with

strace -p 1663

This will attach to the running processes stack trace providing live output of what is going on. At any time you can Ctrl+C

An additional resource is the main error log for Apache this can be found in /var/log/apache2/error.log You'll want to get a decent chunk of the log and skim it for details. If the problem is an ongoing issue running

tail -f /var/log/apache2/error.log

This similar to the strace will run in realtime. For the last N lines replace -f with -# where the # is a positive number like 50, 100, 282, etc.

Solution 2:

Make sure you have proper permissions to stop the service.

If you run:

service apache2 stop

you will not get any error just:

* Stopping web server apache2

Try:

sudo service apache2 stop      

Solution 3:

I too had the same problem, and tried the following:

sudo apache2ctl stop

to stop the service, and

sudo apache2ctl start

to start it again.

It works for me, any possible suggestions are welcome.

Solution 4:

The command systemctl stop apache2 worked for me.