4

I'm trying to work out an annoying issue. We have our server setup with nginx as the main front end, and then Apache2 as the backend for running our Perl scripts. I'm fighting through rewriting some of the Perl scripts (as they were used to running on a much older version of Perl), but I'm having a hell of a job with Apache. When I run:

service apache2 stop

It appears to run:

root@admin:/home/user/web/example.com/logs# service apache2 stop
root@admin:/home/user/web/example.com/logs#

But in fact, it still seems to be running! The command its triggering is:

/etc/init.d/apache2 stop

If I run this manually, I get:

root@admin:/home/user/web/example.com/logs# /etc/init.d/apache2 stop
[ ok ] Stopping apache2 (via systemctl): apache2.service.

..yet when I go to the browser and reload the page, it still loads!!!!! (which means Apache is running)

Anyone got any suggestions as to where I could look? Its driving me nuts! Please let me know if you need any more information.

I see a few processes running:

[] ps aux
root      5948  1.4  0.7 307664 91548 ?        Ss   13:32   0:00 /usr/sbin/apache2 -k start
www-data  5952  0.8  0.9 371080 111964 ?       S    13:32   0:00 /usr/sbin/apache2 -k start
www-data  5953  0.6  0.8 369416 110012 ?       S    13:32   0:00 /usr/sbin/apache2 -k start
www-data  5954  0.5  0.8 369416 110012 ?       S    13:32   0:00 /usr/sbin/apache2 -k start
www-data  5955  0.6  0.8 369416 110012 ?       S    13:32   0:00 /usr/sbin/apache2 -k start
www-data  5956  0.1  0.7 343800 90276 ?        S    13:32   0:00 /usr/sbin/apache2 -k start
www-data  5959  0.0  0.6 307688 79692 ?        S    13:32   0:00 /usr/sbin/apache2 -k start

UPDATE: As suggested, I tried using this to kill it off:

root@admin:~# pgrep apache2 | xargs kill -9
root@admin:~# pgrep apache2 | xargs kill -9
root@admin:~# pgrep apache2 | xargs kill -9
root@admin:~# pgrep apache2 | xargs kill -9
root@admin:~# pgrep apache2 | xargs kill -9
root@admin:~# pgrep apache2 | xargs kill -9

..but right after, I can see it again! (all with the same pid's)

root@admin:~# ps aux | grep apache
root      6080  0.4  0.7 307724 92052 ?        Ss   13:34   0:00 /usr/sbin/apache2 -k start
www-data  6084  0.2  0.8 369400 110024 ?       S    13:34   0:00 /usr/sbin/apache2 -k start
www-data  6085  0.2  0.8 369400 110024 ?       S    13:34   0:00 /usr/sbin/apache2 -k start
www-data  6086  0.1  0.8 369392 110240 ?       S    13:34   0:00 /usr/sbin/apache2 -k start
www-data  6087  0.1  0.8 369400 110024 ?       S    13:34   0:00 /usr/sbin/apache2 -k start
www-data  6088  0.1  0.8 369400 110244 ?       S    13:34   0:00 /usr/sbin/apache2 -k start
www-data  6400  0.3  0.8 369400 110024 ?       S    13:35   0:00 /usr/sbin/apache2 -k start
root      6520  0.0  0.0  14224   972 pts/0    S+   13:37   0:00 grep apache

UPDATE 2:

root@admin:~# killall -9 apache2
apache2: no process found
root@admin:~# ps aux | grep apache2
root      6977  1.2  0.8 315020 99236 ?        Ss   13:41   0:00 /usr/sbin/apache2 -k start
www-data  6981  0.4  0.9 376408 117364 ?       S    13:41   0:00 /usr/sbin/apache2 -k start
www-data  6982  0.4  0.9 376408 117364 ?       S    13:41   0:00 /usr/sbin/apache2 -k start
www-data  6983  0.4  0.9 376408 117364 ?       S    13:41   0:00 /usr/sbin/apache2 -k start
www-data  6984  0.5  0.9 376408 117364 ?       S    13:41   0:00 /usr/sbin/apache2 -k start
www-data  6985  0.0  0.7 315044 87100 ?        S    13:41   0:00 /usr/sbin/apache2 -k start
www-data  6988  0.0  0.7 315044 87100 ?        S    13:41   0:00 /usr/sbin/apache2 -k start
root      7048  0.0  0.0  14224   948 pts/0    S+   13:42   0:00 grep apache2

5 Answers 5

4

Maybe the process hanged for some reason. Did you try a kill -9 and the PID of the apache2 process id?

Alternativelly you could run for a couple of times this command:

pgrep apache2 | xargs kill -9

Then try to start it using /etc/init.d/apache2 start and see if it starts. After that you could take a look at your apache logs and see if you are able to find any useful information that you could use in order to investigate it further...

9
  • thanks. I tried that, but even that doesn't work (although, pgrep apache2 on its own didn't give any output?) Commented Oct 10, 2017 at 13:39
  • if you do a killall -9 apache2 multiple times... it should kill those processes in the end unless they are zombies... In this case you have to find out the main process PID, the initial apache2 process that started the other children/threads etc Commented Oct 10, 2017 at 13:41
  • thanks, but for some reason that gives nothing either (see "Update 2" in the opening question). Thanks! Commented Oct 10, 2017 at 13:43
  • Yeah well it's hard to tell you without actually seeing what's going on... As I said probably it's a zombie process.. Try figuring out which one is the parent process and kill that Commented Oct 10, 2017 at 13:50
  • thanks. The problem is that I've done a full server reboot, and the same problem occurs. Maybe I'll come back to it tomorrow with a fresh mind :) Commented Oct 10, 2017 at 14:01
1

After reading over several answers, none of them thoroughly worked. Now, with the following, I finally made Apache Web Server stop.

Run this to grab the pid of the running process (considering your server runs on port 80)

sudo netstat -lnp | grep ::80

Then kill the process by the pid returned

sudo kill -15 <PID>

Now your server should stop.

1
  • This worked, makes no sense nginx was running the apache2 default page. Commented Dec 27, 2023 at 2:55
0

I stumbled upon the same problem and the steps you took did not work for me either. What worked for me is killing the process responsible for caching after I stopped the server:

sudo service apache2 stop
ps aux | grep apache

www-data  1671  0.0  0.0  19904   172 ?        Ss   10:55   0:00 
/usr/bin/htcacheclean -d 120 -p /var/cache/apache2/mod_cache_disk -l 300M -n

kill 1671

Then after clearing browser's cache performing sudo service apache2 stop/start worked as expected.

0

This worked as expected for me:

sudo kill -15 processID 

where processID is the top parent (lowest number likely) in the process list resturned by:

ps -ef | grep apache2
1
  • Thanks - but my issue seemed to be that Monit was auto restarting it. I managed to get around it by doing service monit stop, and then service apache2 stop Commented Sep 12, 2019 at 6:26
-4

You just have to clear browser cache,then you'll see that it has stopped.After doing this ,start apache2 again and website will change .

1
  • That has nothing to do with it. Why would a browser cache have anything to do with services running on the server? Commented Sep 23, 2020 at 5:16

You must log in to answer this question.

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