Browse Source

Allow restarting a service.

Running "nssm restart <service>" will try to send a stop control
followed by a start control.  It will fail if the service was stopped at
the outset or if it didn't respond to the stop control in a timely
manner.
Iain Patterson 9 years ago
parent
commit
23bed76e3a
3 changed files with 7 additions and 0 deletions
  1. 2 0
      README.txt
  2. BIN
      messages.mc
  3. 5 0
      nssm.cpp

+ 2 - 0
README.txt

@@ -514,6 +514,8 @@ NSSM offers rudimentary service control features.
 
     nssm start <servicename>
 
+    nssm restart <servicename>
+
     nssm stop <servicename>
 
     nssm status <servicename>

BIN
messages.mc


+ 5 - 0
nssm.cpp

@@ -105,6 +105,11 @@ int _tmain(int argc, TCHAR **argv) {
     */
     if (str_equiv(argv[1], _T("start"))) exit(control_service(NSSM_SERVICE_CONTROL_START, argc - 2, argv + 2));
     if (str_equiv(argv[1], _T("stop"))) exit(control_service(SERVICE_CONTROL_STOP, argc - 2, argv + 2));
+    if (str_equiv(argv[1], _T("restart"))) {
+      int ret = control_service(SERVICE_CONTROL_STOP, argc - 2, argv + 2);
+      if (ret) exit(ret);
+      exit(control_service(NSSM_SERVICE_CONTROL_START, argc - 2, argv + 2));
+    }
     if (str_equiv(argv[1], _T("pause"))) exit(control_service(SERVICE_CONTROL_PAUSE, argc - 2, argv + 2));
     if (str_equiv(argv[1], _T("continue"))) exit(control_service(SERVICE_CONTROL_CONTINUE, argc - 2, argv + 2));
     if (str_equiv(argv[1], _T("status"))) exit(control_service(SERVICE_CONTROL_INTERROGATE, argc - 2, argv + 2));