char flags[CMD_LENGTH];\r
char dir[MAX_PATH];\r
bool stopping;\r
+bool allow_restart;\r
unsigned long throttle_delay;\r
+unsigned long stop_method;\r
HANDLE throttle_timer;\r
LARGE_INTEGER throttle_duetime;\r
FILETIME creation_time;\r
/* Start the service */\r
int start_service() {\r
stopping = false;\r
+ allow_restart = true;\r
\r
if (process_handle) return 0;\r
\r
\r
/* Get startup parameters */\r
char *env = 0;\r
- int ret = get_parameters(service_name, exe, sizeof(exe), flags, sizeof(flags), dir, sizeof(dir), &env, &throttle_delay, &si);\r
+ int ret = get_parameters(service_name, exe, sizeof(exe), flags, sizeof(flags), dir, sizeof(dir), &env, &throttle_delay, &stop_method, &si);\r
if (ret) {\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_GET_PARAMETERS_FAILED, service_name, 0);\r
return stop_service(2, true, true);\r
\r
close_output_handles(&si);\r
\r
+ /* Wait for a clean startup. */\r
+ if (WaitForSingleObject(process_handle, throttle_delay) == WAIT_TIMEOUT) throttle = 0;\r
+\r
/* Signal successful start */\r
service_status.dwCurrentState = SERVICE_RUNNING;\r
SetServiceStatus(service_handle, &service_status);\r
\r
- /* Wait for a clean startup. */\r
- if (WaitForSingleObject(process_handle, throttle_delay) == WAIT_TIMEOUT) throttle = 0;\r
-\r
return 0;\r
}\r
\r
/* Stop the service */\r
int stop_service(unsigned long exitcode, bool graceful, bool default_action) {\r
+ allow_restart = false;\r
+ if (wait_handle) UnregisterWait(wait_handle);\r
+\r
if (default_action && ! exitcode && ! graceful) {\r
log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_GRACEFUL_SUICIDE, service_name, exe, exit_action_strings[NSSM_EXIT_UNCLEAN], exit_action_strings[NSSM_EXIT_UNCLEAN], exit_action_strings[NSSM_EXIT_UNCLEAN], exit_action_strings[NSSM_EXIT_REALLY] ,0);\r
graceful = true;\r
if (pid) {\r
/* Shut down service */\r
log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_TERMINATEPROCESS, service_name, exe, 0);\r
- kill_process(service_name, process_handle, pid, 0);\r
+ kill_process(service_name, stop_method, process_handle, pid, 0);\r
}\r
else log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_PROCESS_ALREADY_STOPPED, service_name, exe, 0);\r
\r
}\r
\r
/* Clean up. */\r
- kill_process_tree(service_name, pid, exitcode, pid, &creation_time, &exit_time);\r
+ kill_process_tree(service_name, stop_method, pid, exitcode, pid, &creation_time, &exit_time);\r
\r
/*\r
The why argument is true if our wait timed out or false otherwise.\r
this is a controlled shutdown, and don't take any restart action.\r
*/\r
if (why) return;\r
+ if (! allow_restart) return;\r
\r
/* What action should we take? */\r
int action = NSSM_EXIT_RESTART;\r