1

I want to have multiple httpd services running on a CentOS box, so that if I'm developing a mod_perl script and need to restart one of them, the others can run independently. I had this setup on Windows and am migrating.

Naturally this means separate PID files. I configure mine using the PidFile directive in httpd.conf, and point the init.d script to the same place. It creates the file okay, but does not populate it with all PIDs:

$ sudo killall httpd ; sudo service httpd-dev restart
Stopping httpd: cat: /var/run/httpd/httpd-dev.pid: No such file or directory
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]

Starting httpd:                                            [  OK  ]
$ sudo cat /var/run/httpd/httpd-dev.pid
18279
$ ps -A | grep httpd
18279 ?        00:00:00 httpd
18282 ?        00:00:00 httpd
18283 ?        00:00:00 httpd
18284 ?        00:00:00 httpd
18285 ?        00:00:00 httpd
18286 ?        00:00:00 httpd
18287 ?        00:00:00 httpd
18288 ?        00:00:00 httpd
18289 ?        00:00:00 httpd

...why might this be? Makes it hard to kill just my dev httpd procs later when there will be other httpds. Can't just use 'killall' forever...

$ httpd -v
Server version: Apache/2.2.24 (Unix)

I should note that CentOS 6.4 minimal didn't come with killproc installed, so I changed my init.d to use

kill -9 `cat ${pidfile}`

instead. I guess killproc would search out child PIDs? So I have to install python to install killproc just to use init scripts for httpd?

Kev
  • 15,899
  • 15
  • 79
  • 112

1 Answers1

3

There are two things here:

  • Your single Apache instance might have several PIDs associated with it, depending on the type of MPM selected. However, this should not affect you, since you only need to kill the PID written into the PID file, and that process will kill all the rest of the Apache instance.

  • If you try to run several Apache instances side by side, you'll have to specify a different PID file, one for each. Then you can decide which instances you want to kill - you have to process the PID file of each instance selected. Giving the same PID file to several instances, and expecting them each to put their own PID into the same file, that'll not work.

Laszlo Valko
  • 2,683
  • 25
  • 29
  • re: 1, I don't think that's true, because I did `sudo kill -9 18279` and then `ps -A | grep httpd` still shows all the others. Am I using the wrong MPM? re: 2, I didn't flesh it out quite as much in my question but that's what I meant by the "Naturally..." bit; that's why it's called `httpd-dev.pid` and the others will have different names (once I get this one able to be restarted....) – Kev Oct 01 '13 at 17:45
  • 1
    Well, maybe that's because kill -9 is not the proper way to stop Apache... For real multithreaded MPMs, even kill -9 should work properly. For forking MPMs, it has a high chance that the forked children will not immediately (or ever) notice the death of their parent, and clearly the parent cannot send quit signals to its children. As far as I know, there's no provision in Apache to get the PIDs of the children for forking MPMs. Also, if you run any CGI, or anything forked from Apache (eg: a PHP script starting external programs), those processes are not managed by Apache at all. – Laszlo Valko Oct 01 '13 at 17:56
  • Ah! I bet I took that config over because forking is the only one you can use on win32. I'll try switching to real multithreaded. Thanks! – Kev Oct 01 '13 at 18:08
  • Oh, wait, MPMs are compiled in. Mine was with 'prefork' over on CentOS here. But that's the default for unix...so...I'm a bit confused. `kill -9` is not proper, but I'm sure an undeclared dependency `killproc` which depends on python is also not proper? so you just normally can't restart httpd cleanly by default? why bother having an init.d script then? – Kev Oct 02 '13 at 00:21
  • 1
    You use kill -TERM on the PID in the PID file, and it should terminate. Actually, apachectl -k stop should be doing something similar. – Laszlo Valko Oct 02 '13 at 00:35
  • Aha, that's the ticket. Thanks! – Kev Oct 02 '13 at 01:02