X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=service.cpp;h=ac90ecb284232acc4c83bdc5b6cb6ac7ff2dc148;hb=dc414f5c8eb8a534e759fe5326c2026f9e9f71a7;hp=873b8a8f537b423a968a94cb38ad7eaf65246650;hpb=23b8173ce06a843f18a9269fc6f7d4d0d224cd4c;p=nssm.git diff --git a/service.cpp b/service.cpp index 873b8a8..ac90ecb 100644 --- a/service.cpp +++ b/service.cpp @@ -11,6 +11,7 @@ char exe[EXE_LENGTH]; char flags[CMD_LENGTH]; char dir[MAX_PATH]; bool stopping; +bool allow_restart; unsigned long throttle_delay; unsigned long stop_method; HANDLE throttle_timer; @@ -359,6 +360,7 @@ unsigned long WINAPI service_control_handler(unsigned long control, unsigned lon /* Start the service */ int start_service() { stopping = false; + allow_restart = true; if (process_handle) return 0; @@ -404,18 +406,21 @@ int start_service() { close_output_handles(&si); + /* Wait for a clean startup. */ + if (WaitForSingleObject(process_handle, throttle_delay) == WAIT_TIMEOUT) throttle = 0; + /* Signal successful start */ service_status.dwCurrentState = SERVICE_RUNNING; SetServiceStatus(service_handle, &service_status); - /* Wait for a clean startup. */ - if (WaitForSingleObject(process_handle, throttle_delay) == WAIT_TIMEOUT) throttle = 0; - return 0; } /* Stop the service */ int stop_service(unsigned long exitcode, bool graceful, bool default_action) { + allow_restart = false; + if (wait_handle) UnregisterWait(wait_handle); + if (default_action && ! exitcode && ! graceful) { 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); graceful = true; @@ -490,6 +495,7 @@ void CALLBACK end_service(void *arg, unsigned char why) { this is a controlled shutdown, and don't take any restart action. */ if (why) return; + if (! allow_restart) return; /* What action should we take? */ int action = NSSM_EXIT_RESTART;