[users@httpd] Re: Controlling Apache Win32 as a Console App

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Joost de Heer wrote:
If you want to script this, get something like ptree (from the resource
kit) or pskill (from sysinternals) to kill the process.


I just remembered that ptree requires a service to be installed, so drop
that option. pskill is what you want.


Thanks for the advice. That seems to work just fine.

I also wrote a small, quick and dirty Win32 console app which waits for the console to be closed and then runs a second process, allowing both mySQL and Apache to run in the same console and both be shut down properly when the window is closed. I've attached the source code in case anyone else tries to do the same kind of thing as I have tried. In my setup, runonclose is called with a cmd script as its parameter.

All the best,
-Martin


#include <windows.h>
#include <stdio.h>
#include <string.h>

char * cmdline = NULL;

BOOL WINAPI ConsoleClose(DWORD CEvent) {

	switch(CEvent) {
		case CTRL_C_EVENT:
		case CTRL_BREAK_EVENT:
		case CTRL_CLOSE_EVENT:
		case CTRL_LOGOFF_EVENT:
		case CTRL_SHUTDOWN_EVENT: {
			STARTUPINFO si;
			PROCESS_INFORMATION pi;
			ZeroMemory( &si, sizeof(si) );
			si.cb = sizeof(si);
			ZeroMemory( &pi, sizeof(pi) );

			CreateProcess(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
			WaitForSingleObject(pi.hThread, 10000);
			ExitProcess(0);
		} break;
    }

    return TRUE;
}

int main(int argc, char** argv) {

	if (argc < 2) {
		printf("Usage: runonclose <commandline>\n");
		return -3;
	}
	cmdline = argv[1];

	if (! SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleClose,TRUE)) {
		printf("Failed to install console handler.\n");
		return -1;
	}

	while (fgetc(stdin)) {}

	return -2;
}

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux