Don't fail to restart if the service is stopped.
[nssm.git] / service.cpp
index a86d744..9cdf9de 100644 (file)
@@ -1214,6 +1214,9 @@ int control_service(unsigned long control, int argc, TCHAR **argv) {
     else {\r
       CloseHandle(service_handle);\r
       _ftprintf(stderr, _T("%s: %s: %s"), canonical_name, service_control_text(control), error_string(error));\r
+      if (error == ERROR_SERVICE_NOT_ACTIVE) {\r
+        if (control == SERVICE_CONTROL_SHUTDOWN || control == SERVICE_CONTROL_STOP) return 0;\r
+      }\r
       return 1;\r
     }\r
   }\r
@@ -1612,6 +1615,8 @@ int stop_service(nssm_service_t *service, unsigned long exitcode, bool graceful,
     service->wait_handle = 0;\r
   }\r
 \r
+  service->rotate_stdout_online = service->rotate_stderr_online = NSSM_ROTATE_OFFLINE;\r
+\r
   if (default_action && ! exitcode && ! graceful) {\r
     log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_GRACEFUL_SUICIDE, service->name, service->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
@@ -1659,6 +1664,8 @@ void CALLBACK end_service(void *arg, unsigned char why) {
 \r
   service->stopping = true;\r
 \r
+  service->rotate_stdout_online = service->rotate_stderr_online = NSSM_ROTATE_OFFLINE;\r
+\r
   /* Check exit code */\r
   unsigned long exitcode = 0;\r
   TCHAR code[16];\r