From 2e0e3ebbaa2b2a1398d4bc4b7d836e38d93d63eb Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 18 Jan 2010 22:15:43 +0000
Subject: [PATCH] Fix for issue 4381 (Enabling windows service once server started fails to detect server status) If the server is running, launch the service after the service has been enabled.  The code of the service (native code in service.c) already handles the case where the server is running before the service code has been launched.

---
 opends/src/server/org/opends/server/tools/ConfigureWindowsService.java |   35 +++++++++++++++++++++++++++++++----
 1 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/ConfigureWindowsService.java b/opends/src/server/org/opends/server/tools/ConfigureWindowsService.java
index e79fdd4..37ab80a2 100644
--- a/opends/src/server/org/opends/server/tools/ConfigureWindowsService.java
+++ b/opends/src/server/org/opends/server/tools/ConfigureWindowsService.java
@@ -22,10 +22,11 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008-2009 Sun Microsystems, Inc.
+ *      Copyright 2008-2010 Sun Microsystems, Inc.
  */
 
 package org.opends.server.tools;
+import org.opends.guitools.controlpanel.util.Utilities;
 import org.opends.messages.Message;
 
 import java.io.BufferedReader;
@@ -462,13 +463,39 @@
 
     try
     {
+      boolean isServerRunning = Utilities.isServerRunning(
+          new File(serverRoot));
+
       int resultCode = Runtime.getRuntime().exec(cmd).waitFor();
       switch (resultCode)
       {
       case 0:
-        returnValue = SERVICE_ENABLE_SUCCESS;
-        msg = INFO_WINDOWS_SERVICE_SUCCESSULLY_ENABLED.get();
-        out.println(wrapText(msg, MAX_LINE_WIDTH));
+        if (isServerRunning)
+        {
+          // We have to launch the windows service.  The service code already
+          // handles this case (the service binary is executed when the server
+          // already runs).
+          returnValue = StartWindowsService.startWindowsService(out, err);
+          if (returnValue == 0)
+          {
+            returnValue = SERVICE_ENABLE_SUCCESS;
+            msg = INFO_WINDOWS_SERVICE_SUCCESSULLY_ENABLED.get();
+            out.println(wrapText(msg, MAX_LINE_WIDTH));
+          }
+          else
+          {
+            msg = ERR_WINDOWS_SERVICE_ENABLING_ERROR_STARTING_SERVER.get(
+                returnValue);
+            returnValue = SERVICE_ENABLE_ERROR;
+            err.println(wrapText(msg, MAX_LINE_WIDTH));
+          }
+        }
+        else
+        {
+          returnValue = SERVICE_ENABLE_SUCCESS;
+          msg = INFO_WINDOWS_SERVICE_SUCCESSULLY_ENABLED.get();
+          out.println(wrapText(msg, MAX_LINE_WIDTH));
+        }
         break;
       case 1:
         returnValue = SERVICE_ALREADY_ENABLED;

--
Gitblit v1.10.0