Apache, once started from command line (apache.exe) cannot be stopped via command line (apache.exe -k stop). This seems to be connected with bug 14555, but also appears in the most recent version (2.0.48) under Windows XP. We need this feature to embed Apache into some other software, which cannot use apache as a service.
Applied same priority and severity as bug 14555.
Talking to JanC revealed this bug is not connected with the Win9x bug. In Win9x, the "apache -k stop" process hangs completely, while on Win XP it says "There is no apache service running" and terminates. JanC suspects from the error message the code only looks for running services, which is certainly not what the docs describe. Killing Apache using it's PID does not work around this problem, as Apache starts child processes, which are not affected if the main process is killed.
The -k is only for controlling the apache service ( the code says it is only for dealing with the SCM - i.e. services) and the docs: http://httpd.apache.org/docs-2.0/platform/windows.html show that -k is used when running apache as a service. If you still need to shutdown the process *i know the bug is quite old ;)* you could search through all processes, find each apache process and search the parent pids until you get to the top parent then close that first then each of the children (for a hint on getting parent pids look at http://www.codeproject.com/threads/ParentPID.asp )
Looks like -k was bring used in the wrong way.
So there is no other way to shut down an apache process not running as a service? We cannot just kill all the httpd processes found since there may be several servers running on the same machine. Finding out which process tree to kill is what works marvelous on unix machines - thought that Windows might behave similar, especially since it was the case with Apache httpd 1.x. Currently our workaround is really to kill the process by pid. There is no process hierarchy as by httpd.conf we tell apache not to spawn child processes, so killing the one parent is sufficient. To find the correct PID we keep the handle to the process which is returned by the system call to spawn the apache process.
I'm a bit confused. The referenced docs at: http://httpd.apache.org/docs-2.0/platform/windows.html show the "-k install", "-k uninstall" and "-k start" start options only in the "Running Apache as a Service" section, but list "-k shutdown/stop" and "-k restart" under BOTH "Running Apache as a Service" AND "Running Apache as a Console Application". This would seem to imply that I SHOULD be able to use "-k shutdown" on an Apache running in a console (as I could in 1.3).
*** Bug 36556 has been marked as a duplicate of this bug. ***
apache -k stop does not support shutting down a console, and the console mode really isn't designed for such things. httpd is a daemon (a service, in windows parlance) so there isn't a large amount of attention paid to it. Sending a control C event to the console will terminate apache. If you were running five of them, how do you suppose -k stop would know which to shut down? In any case, I agree it's a documentation bug that should be resolved by removing the -k stop from featured "Running Apache as a Console Application" options.
We had a deadline that passed long ago & ended up working around this by writing a trivial .exe that accepts -f and -k command line options (that have the same meaning as the corresponding apache command line options), finds the PidFile line in the apache config file, reads the pid file, then calls SetEvent() on the event indicated by the pid and the -k parameter. It's been awhile, but IIRC the majority of this logic was copied from the code that made this work in 1.3. I looked at reincorporating this function into the 2.x base, but schedules were tight & it was quicker to write a standalone .exe. As I said, we worked around this problem long ago so I don't really have a strong interest in how this bug is addressed. If there is any interest in our little hack, the company I work for contributes pretty regularly to the Apache web server & I can't imagine they would mind making the source for our simple .exe available if I asked. (In reply to comment #8) > Sending a control C event to the console will terminate apache. If you were > running five of them, how do you suppose -k stop would know which to shut down? By consulting the -f parameter (see description above).
Mike, I concur it's worth fixing; solving it in the MPM isn't really that hard (using the pidfile as on unix). I'll leave this assigned for consideration and for want of a patch (that I don't have cycles to write, right now).
Correct priority in relation to supported uses of httpd/win32.
still valid tested on: Windows 7 Ultimate 64 Bit Apache 2.2.21 not conform with released documentation: http://httpd.apache.org/docs/2.2/platform/windows.html#wincons