3

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
Andrew Newby
  • 1,102
  • 2
  • 25
  • 58

5 Answers5

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...

Bogdan Stoica
  • 403
  • 4
  • 9
  • thanks. I tried that, but even that doesn't work (although, `pgrep apache2 ` on its own didn't give any output?) – Andrew Newby Oct 10 '17 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 – Bogdan Stoica Oct 10 '17 at 13:41
  • thanks, but for some reason that gives nothing either (see "Update 2" in the opening question). Thanks! – Andrew Newby Oct 10 '17 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 – Bogdan Stoica Oct 10 '17 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 :) – Andrew Newby Oct 10 '17 at 14:01
  • Do you have any cron job related to apache2 that might cause this?! – Bogdan Stoica Oct 10 '17 at 14:04
  • we have Monit setup for Apache, but its set on a 240 second check loop - so shouldn't be rebooting it right away :/ – Andrew Newby Oct 10 '17 at 14:05
  • Yeah well you could try disabling monit just for testing purposes and see how that goes. a bad monit config could try to restart apache over and over... – Bogdan Stoica Oct 10 '17 at 14:28
  • Do all the Apache PIDs change when you restart? Maybe there us an unit script or some such that us automatically respawning apache when it dies? – davidgo Sep 12 '19 at 05:21
0

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.

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
RalfFriedl
  • 3,108
  • 4
  • 13
  • 17
  • 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` – Andrew Newby Sep 12 '19 at 06: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 .

Rufat
  • 1
  • 1