6

What can cause httpd to start automatically after stopping it?

In a bash script I need to first stop apache web server. This is the script:

apachectl stop;
while pgrep httpd; do sleep 1; done
echo "[Apache server stopped]"

When I run the script it prints running apache processes until there isn't any running process and prints [Apache server stopped]

Then running the command pgrep httpd prints nothing, but if I enter a website hosted by the server, then pgrep httpd prints some httpd processes.

Is this the right way to stop apache? Why does it start automatically after running apachectl stop? If it is related to KeepAliveTime, how do I force the running child processes to stop?

Edit: This is also true for running service httpd stop or apachectl stop commands in command line.

  • 2
    You probably have a service monitor running that only sees the service exiting and tries to resume operations. – Bratchley Apr 3 '14 at 19:25
  • just to double-check something: check for the presence of /usr/bin/systemctl, please. if this is a systemd system I know exactly what's going on. – strugee Apr 7 '14 at 2:24
  • inetd service ? – Kiwy Apr 7 '14 at 9:32
  • @strugee /usr/bin/systemctl doesn't exists. – Omid Apr 8 '14 at 20:24
  • @Kiwy inetd is not in the service [TAB] list – Omid Apr 8 '14 at 20:25
2

upstart, the service manager, can restart httpd if it is set to respawn.

apachectl stop stop's the process without notifying upstart

Try:

service httpd stop

By the way, when you issue any of the stop like commands to apache it will stop accepting new connections. The gracefuls will additionally allow it to complete any currently open connections.

  • 1
    OP has "CentOS" tagged, but I agree that something similar is probably what's going on. They may have some sort of service monitor running. – Bratchley Apr 3 '14 at 19:23
  • What do you mean about the centos tag? – Matt Apr 3 '14 at 20:43
  • @mtm Thanks, but as JoelDavis mentioned, I use CentOS not Ubuntu – Omid Apr 3 '14 at 20:46
  • @Omid Centos6? init --help | tail -1 – Matt Apr 3 '14 at 20:51
  • Yes. Centos6. init --help shows that it uses upstart! but stop httpd returns this error: stop: Unknown job: httpd – Omid Apr 3 '14 at 20:57
2
+50

Confirming a service

On CentOS 6 I would investigate if the httpd service is accessible.

$ service --status-all |& grep httpd
httpd is stopped

You can disable this service using chkconfig:

$ chkconfig --list | grep httpd
httpd           0:off   1:off   2:off   3:on    4:on    5:on    6:off

$ sudo chkconfig httpd off

$ chkconfig --list | grep httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off

But it keeps starting when I access it?

Since you're dealing with CentOS 6 you're likely using Upstart. You can see if httpd the service is under its control.

$ initctl list

You'll see it in the list, I do not have this configuration to show. I would assume based on your description of the issue that your system has httpd set like this:

httpd stop/waiting

Which, as I understand it, means that if Upstart sees that service being accessed, it will start it back up. Upstart will maintain a service script for httpd under /etc/init if this is the case. You'll want to go inside that file and disable the service and reload the config. It likely has a respawn section which is causing this:

Example

$ more /etc/init/prefdm.conf 
# prefdm - preferred display manager
#
# Starts gdm/xdm/etc by preference

start on stopped rc RUNLEVEL=5

stop on starting rc RUNLEVEL=[!5]

console output
respawn
respawn limit 10 120
exec /etc/X11/prefdm -nodaemon

References

0

Look for it in /etc/inittab, could be that someone put it to respawn.

  • content of the file is: id:3:initdefault: – Omid Apr 8 '14 at 20:23
  • Hence that is not the problem. – periket2000 Apr 9 '14 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.