Read registry before each restart.
authorIain Patterson <me@iain.cx>
Thu, 17 Feb 2011 00:05:06 +0000 (00:05 +0000)
committerIain Patterson <me@iain.cx>
Thu, 17 Feb 2011 00:05:06 +0000 (00:05 +0000)
Read Application, AppDirectory and AppParameters before each restart so
a change to any one doesn't require restarting NSSM itself.

service.cpp

index a90d508..a400ebd 100644 (file)
@@ -198,17 +198,6 @@ void WINAPI service_main(unsigned long argc, char **argv) {
     return;\r
   }\r
 \r
-  /* Get startup parameters */\r
-  int ret = get_parameters(argv[0], exe, sizeof(exe), flags, sizeof(flags), dir, sizeof(dir));\r
-  if (ret) {\r
-    log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_GET_PARAMETERS_FAILED, argv[0], 0);\r
-    service_status.dwCurrentState = SERVICE_STOPPED;\r
-    /* An accurate, if not particularly helpful, status */\r
-    service_status.dwWin32ExitCode = ERROR_SERVICE_NOT_ACTIVE;\r
-    SetServiceStatus(service_handle, &service_status);\r
-    return;\r
-  }\r
-\r
   service_status.dwCurrentState = SERVICE_START_PENDING;\r
   service_status.dwWaitHint = NSSM_RESET_THROTTLE_RESTART + NSSM_WAITHINT_MARGIN;\r
   SetServiceStatus(service_handle, &service_status);\r
@@ -304,6 +293,13 @@ int start_service() {
   PROCESS_INFORMATION pi;\r
   ZeroMemory(&pi, sizeof(pi));\r
 \r
+  /* Get startup parameters */\r
+  int ret = get_parameters(service_name, exe, sizeof(exe), flags, sizeof(flags), dir, sizeof(dir));\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
+\r
   /* Launch executable with arguments */\r
   char cmd[CMD_LENGTH];\r
   if (_snprintf(cmd, sizeof(cmd), "%s %s", exe, flags) < 0) {\r