const char *ap_server_argv0;
-API_VAR_EXPORT const char *ap_server_root;
+//API_VAR_IMPORT const char *ap_server_root;
+const char *ap_server_root;
ap_array_header_t *ap_server_pre_read_config;
ap_array_header_t *ap_server_post_read_config;
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Usage: %s [-D name] [-d directory] [-f file]", bin);
#endif
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-C \"directive\"] [-c \"directive\"]", pad);
+#ifdef WIN32
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-k restart|shutdown|start]", pad);
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-n service_name]", pad);
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-i] [-u]", pad);
+#endif
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]", pad);
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Options:");
#ifdef SHARED_CORE
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -f file : specify an alternate ServerConfigFile");
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -C \"directive\" : process directive before reading config files");
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -c \"directive\" : process directive after reading config files");
+#ifdef WIN32
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -n name : set service name and use its ServerConfigFile");
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k shutdown : tell running Apache to shutdown");
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k restart : tell running Apache to do a graceful restart");
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k start : tell Apache to start");
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -i : install an Apache service");
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -u : uninstall an Apache service");
+#endif
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -v : show version number");
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -V : show compile settings");
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -h : list available command line options (this page)");
ap_context_t *ptemp; /* Pool for temporary config stuff, reset often */
ap_context_t *pcommands; /* Pool for -C and -c switches */
+#ifdef WIN32
+ char *signal = NULL;
+#endif
+
ap_server_argv0 = process->short_name;
ap_util_uri_init();
ap_server_post_read_config = ap_make_array(pcommands, 1, sizeof(char *));
ap_server_config_defines = ap_make_array(pcommands, 1, sizeof(char *));
- while (ap_getopt(pcommands, argc, argv, "C:c:d:f:vVlLth", &c) == APR_SUCCESS) {
+ while (ap_getopt(pcommands, argc, argv, "C:c:d:f:k:vVlLth", &c) == APR_SUCCESS) {
char **new;
switch (c) {
case 'c':
case 'f':
confname = ap_optarg;
break;
+#ifdef WIN32
+ case 'k':
+ signal = ap_optarg;
+ break;
+#endif
case 'v':
printf("Server version: %s\n", ap_get_server_version());
printf("Server built: %s\n", ap_get_server_built());
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Syntax OK\n");
destroy_and_exit_process(process, 0);
}
+#ifdef WIN32
+ if (signal) {
+ ap_signal_parent(pconf, signal, ap_server_root);
+ destroy_and_exit_process(process, 0);
+ }
+#endif
ap_clear_pool(plog);
ap_run_open_logs(pconf, plog, ptemp, server_conf);
ap_post_config_hook(pconf, plog, ptemp, server_conf);
* Definitions of WINNT MPM specific config globals
*/
-char *ap_pid_fname=NULL;
+static char *ap_pid_fname = NULL;
static int ap_threads_per_child = 0;
static int workers_may_exit = 0;
static int max_requests_per_child = 0;
{
signal_parent(0);
}
+
+void ap_signal_parent(ap_context_t *p, const char* signal,
+ const char* server_root)
+{
+ HANDLE event;
+ char prefix[20];
+ char *EventName;
+ FILE *fp;
+ int nread;
+ char *fname;
+ int end;
+
+ printf("signal = %s\n", signal);
+
+ fname = ap_server_root_relative (p, ap_pid_fname);
+
+ fp = fopen(fname, "r");
+ if (!fp) {
+ printf("Cannot read apache PID file %s. Error = %d\n", fname, errno);
+ return;
+ }
+ prefix[0] = 'a';
+ prefix[1] = 'p';
+
+ nread = fread(prefix+2, 1, sizeof(prefix)-3, fp);
+ if (nread == 0) {
+ fclose(fp);
+ printf("PID file %s was empty\n", fname);
+ return;
+ }
+ fclose(fp);
+
+ /* Terminate the prefix string */
+ end = 2 + nread - 1;
+ while (end > 0 && (prefix[end] == '\r' || prefix[end] == '\n'))
+ end--;
+ prefix[end + 1] = '\0';
+
+ /* Build the event name. Should be one of the following...
+ * apPID_shutdown
+ * apPID_restart
+ */
+ EventName = ap_pstrcat(p,prefix,"_",signal,NULL);
+ printf("event name = %s\n", EventName);
+ event = OpenEvent(EVENT_ALL_ACCESS, FALSE, EventName);
+ printf("event handle = %d\n", event);
+ if (event == NULL) {
+ printf("Unable to open event %s.\n", EventName);
+ return;
+ }
+ SetEvent(event);
+ ResetEvent(event);
+ CloseHandle(event);
+ return;
+}
/*
* Initialise the signal names, in the global variables signal_name_prefix,
* signal_restart_name and signal_shutdown_name.
int rv;
char buf[1024];
char *pCommand;
-
+ int i;
STARTUPINFO si; /* Filled in prior to call to CreateProcess */
PROCESS_INFORMATION pi; /* filled in on call to CreateProces */
return -1;
}
- //pCommand = ap_psprintf(p, "\"%s\" -f \"%s\"", buf, ap_server_confname);
- pCommand = ap_psprintf(p, "\"%s\" -f \"%s\"", buf, SERVER_CONFIG_FILE);
+ /* Build the command line */
+ pCommand = ap_psprintf(p, "\"%s\"", buf);
+ for (i = 1; i < server_conf->process->argc; i++) {
+ pCommand = ap_pstrcat(p, pCommand, " \"", server_conf->process->argv[i], "\"", NULL);
+ }
/* Create a pipe to send socket info to the child */
if (!CreatePipe(&hPipeRead, &hPipeWrite, &sa, 0)) {
/* Create child process
* Should only be one in this version of Apache for WIN32
*/
+#if 1
+// ReportStatusToSCMgr(SERVICE_START_PENDING, NO_ERROR, 3000);
+#else
+// service_set_status(SERVICE_START_PENDING);
+#endif
while (remaining_children_to_start--) {
if (create_process(pconf, process_handles, process_kill_events,
¤t_live_processes) < 0) {
goto die_now;
}
}
-
- /* service_set_status(SERVICE_RUNNING);*/
+#if 1
+// ReportStatusToSCMgr(SERVICE_RUNNING, NO_ERROR, 3000);
+#else
+// service_set_status(SERVICE_RUNNING);
+#endif
restart_pending = shutdown_pending = 0;
/* Wait for shutdown or restart events or for child death */
else {
/* This is the parent */
parent_pid = my_pid = getpid();
- ap_log_pid(pconf, ap_pid_fname);
+
}
ap_listen_pre_config();
ap_clear_pool(plog);
ap_open_logs(server_conf, plog);
- setup_signal_names(ap_psprintf(pconf,"ap%d", parent_pid));
+ setup_signal_names(ap_psprintf(pconf,"ap%d", parent_pid));
if (!restart) {
- /* service_set_status(SERVICE_START_PENDING);*/
+ ap_log_pid(pconf, ap_pid_fname);
+#if 1
+// ReportStatusToSCMgr(SERVICE_START_PENDING, NO_ERROR, 3000);
+#else
+// service_set_status(SERVICE_START_PENDING);
+#endif
AMCSocketInitialize();
// setup_signal_names(ap_psprintf(pconf,"ap%d", parent_pid));
CloseHandle(restart_event);
CloseHandle(shutdown_event);
AMCSocketCleanup();
- /* service_set_status(SERVICE_STOPPED); */
+#if 1
+// ReportStatusToSCMgr(SERVICE_STOPPED, NO_ERROR, 3000);
+#else
+// service_set_status(SERVICE_STOPPED);
+#endif
}
}
return !restart;