X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=service.cpp;h=b8c73ef435a15f606473dfc8979a74f8f34322f4;hb=2cd1c7c29ef4d2d3df3c5afd3ca6c788aede2bef;hp=93b7d4a53d8b9f003d189d72153f2707dd1b589b;hpb=53371f115d94fbbc7e5cb60853b9e4a5d356d4b0;p=nssm.git diff --git a/service.cpp b/service.cpp index 93b7d4a..b8c73ef 100644 --- a/service.cpp +++ b/service.cpp @@ -162,9 +162,9 @@ unsigned long priority_index_to_constant(int index) { return NORMAL_PRIORITY_CLASS; } -static inline int throttle_milliseconds(unsigned long throttle) { +static inline unsigned long throttle_milliseconds(unsigned long throttle) { /* pow() operates on doubles. */ - int ret = 1; for (unsigned long i = 1; i < throttle; i++) ret *= 2; + unsigned long ret = 1; for (unsigned long i = 1; i < throttle; i++) ret *= 2; return ret * 1000; } @@ -1281,6 +1281,7 @@ TCHAR *service_control_text(unsigned long control) { case SERVICE_CONTROL_PAUSE: return _T("PAUSE"); case SERVICE_CONTROL_CONTINUE: return _T("CONTINUE"); case SERVICE_CONTROL_INTERROGATE: return _T("INTERROGATE"); + case NSSM_SERVICE_CONTROL_ROTATE: return _T("ROTATE"); default: return 0; } } @@ -1368,6 +1369,12 @@ unsigned long WINAPI service_control_handler(unsigned long control, unsigned lon */ log_service_control(service->name, control, false); return ERROR_CALL_NOT_IMPLEMENTED; + + case NSSM_SERVICE_CONTROL_ROTATE: + log_service_control(service->name, control, true); + if (service->rotate_stdout_online) service->rotate_stdout_online = NSSM_ROTATE_ONLINE_ASAP; + if (service->rotate_stdout_online) service->rotate_stderr_online = NSSM_ROTATE_ONLINE_ASAP; + return NO_ERROR; } /* Unknown control */ @@ -1431,7 +1438,7 @@ int start_service(nssm_service_t *service) { if (get_process_creation_time(service->process_handle, &service->creation_time)) ZeroMemory(&service->creation_time, sizeof(service->creation_time)); - close_output_handles(&si); + close_output_handles(&si, ! service->rotate_stdout_online, ! service->rotate_stderr_online); if (service->affinity) { /* @@ -1490,6 +1497,9 @@ int start_service(nssm_service_t *service) { else service->throttle = 0; } + /* Ensure the restart delay is always applied. */ + if (service->restart_delay && ! service->throttle) service->throttle++; + return 0; } @@ -1632,14 +1642,22 @@ void throttle_restart(nssm_service_t *service) { /* This can't be a restart if the service is already running. */ if (! service->throttle++) return; - int ms = throttle_milliseconds(service->throttle); + unsigned long ms; + unsigned long throttle_ms = throttle_milliseconds(service->throttle); + TCHAR threshold[8], milliseconds[8]; + + if (service->restart_delay > throttle_ms) ms = service->restart_delay; + else ms = throttle_ms; if (service->throttle > 7) service->throttle = 8; - TCHAR threshold[8], milliseconds[8]; - _sntprintf_s(threshold, _countof(threshold), _TRUNCATE, _T("%lu"), service->throttle_delay); _sntprintf_s(milliseconds, _countof(milliseconds), _TRUNCATE, _T("%lu"), ms); - log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_THROTTLED, service->name, threshold, milliseconds, 0); + + if (service->throttle == 1 && service->restart_delay > throttle_ms) log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_RESTART_DELAY, service->name, milliseconds, 0); + else { + _sntprintf_s(threshold, _countof(threshold), _TRUNCATE, _T("%lu"), service->throttle_delay); + log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_THROTTLED, service->name, threshold, milliseconds, 0); + } if (use_critical_section) EnterCriticalSection(&service->throttle_section); else if (service->throttle_timer) {