You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by James Blond <jb...@gmail.com> on 2006/08/16 15:36:28 UTC
Missing restart parameter under Win32
Hi,
I'm missing a parameter for httpd.exe under Windows. When Apache is
installed as service there is no Problem using the -k restart | stop |
start
But when I run it under the console there is no way to stop apache as
pressing ctrl + c
There is a standalone file that can do this. I think it is easy to
port that as a new paramter into apache for win32.
For *nix system there is the apachectl to do that!
Mario
#include <windows.h>
#include <stdio.h>
static HANDLE shutdown_event = NULL; /* used to signal Apache 2 to shutdown */
static HANDLE restart_event = NULL; /* used to signal Apache 2 to restart */
main(int argc, char **argv)
{ char *signal_shutdown_name = (char *) calloc(128,1);
BOOL result = 0;
char *pidfilename = (char *) calloc(256,1);
char *pidbuff = (char *) calloc(11,1);
FILE *pidfile = NULL;
char *action_name[] = {"shutdown","restart"};
int action = 0;
if (argc < 2)
{ printf("Usage:\n httpd_shutdown Apache_rootdir [restart]\n");
return 2;
}
if (argc > 2 && _stricmp(argv[2],"restart") == 0) action=1; //
restart instead of shutdown
sprintf(pidfilename, "%s\\logs\\httpd.pid", argv[1]); //
find the PID file and open it
pidfile = fopen(pidfilename,"r");
if (pidfile == NULL)
{ fprintf( stderr, "Error opening \"%s\"\n\t%s\n", pidfilename,
_strerror(NULL) );
return 1;
}
fread( pidbuff, sizeof( char ), 10, pidfile );
sprintf(signal_shutdown_name, "ap%d_%s", atoi(pidbuff),
action_name[action] ); // like "ap1234_shutdown"
printf("setting apache PID %d shutdown event: %s\n",
atoi(pidbuff), signal_shutdown_name);
shutdown_event = OpenEvent(EVENT_MODIFY_STATE, FALSE,
signal_shutdown_name); // get the (existing) event
if (shutdown_event == NULL)
{ fprintf( stderr, "Could not acquire event named
\"%s\"\n\t%s\n", signal_shutdown_name, _strerror(NULL) );
return 1;
}
result = SetEvent(shutdown_event);
// set the event
if (!result)
{ fprintf( stderr, "Acquired but could not set event named
\"%s\"\n\t%s\n",
signal_shutdown_name, _strerror(NULL) );
return 1;
}
return result;
}