From 1cbead747c938b98fb309d8b7d616b4fe318d53e Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Thu, 19 May 2011 17:20:24 +0000
Subject: [PATCH] Fix OPENDJ-161 - Rebranding Windows service integration to OpenDJ

---
 opends/src/build-tools/windows/opendj_service.exe.manifest             |    2 
 opends/src/server/org/opends/server/tools/ConfigureWindowsService.java |   27 ++++----
 opends/src/build-tools/windows/service.c                               |   74 +++++++++++++-----------
 opends/src/build-tools/windows/EventLogMsg.mc                          |   35 ++++++-----
 opends/src/build-tools/windows/Makefile                                |    5 +
 5 files changed, 77 insertions(+), 66 deletions(-)

diff --git a/opends/src/build-tools/windows/EventLogMsg.mc b/opends/src/build-tools/windows/EventLogMsg.mc
index bad9b7c..11204e4 100644
--- a/opends/src/build-tools/windows/EventLogMsg.mc
+++ b/opends/src/build-tools/windows/EventLogMsg.mc
@@ -23,6 +23,7 @@
 ; *
 ; *
 ; *      Copyright 2008-2010 Sun Microsystems, Inc.
+; *      Portions Copyright 2011 ForgeRock AS
 ; */
 ;/*
 ; * ==========================================================================
@@ -51,7 +52,7 @@
    )
 
 FacilityNames = (
-   OPENDS	= 0xFA0 : WIN_FACILITY_NAME_OPENDS
+   OPENDJ	= 0xFA0 : WIN_FACILITY_NAME_OPENDJ
    )
 
 
@@ -63,48 +64,48 @@
 
 MessageId    = 0x1
 Severity     = Success
-Facility     = OPENDS
+Facility     = OPENDJ
 SymbolicName = WIN_EVENT_ID_SERVER_STARTED
 Language     = English
-OpenDS has started.
-OpenDS is in %1.
+OpenDJ has started.
+OpenDJ is in %1.
 .
 MessageId    = 0x2
 Severity     = Success
-Facility     = OPENDS
+Facility     = OPENDJ
 SymbolicName = WIN_EVENT_ID_SERVER_STOP
 Language     = English
-OpenDS has shutdown.
-OpenDS is in %1.
+OpenDJ has shutdown.
+OpenDJ is in %1.
 .
 MessageId    = 0x3
 Severity     = Error
-Facility     = OPENDS
+Facility     = OPENDJ
 SymbolicName = WIN_EVENT_ID_SERVER_START_FAILED
 Language     = English
-OpenDS failed in startup.
-OpenDS is in %1.
+OpenDJ failed in startup.
+OpenDJ is in %1.
 .
 MessageId    = 0x4
 Severity     = Error
-Facility     = OPENDS
+Facility     = OPENDJ
 SymbolicName = WIN_EVENT_ID_SERVER_STOP_FAILED
 Language     = English
-OpenDS failed in stop.
-OpenDS is in %1.
+OpenDJ failed in stop.
+OpenDJ is in %1.
 .
 MessageId    = 0x5
 Severity     = Informational
-Facility     = OPENDS
+Facility     = OPENDJ
 SymbolicName = WIN_EVENT_ID_DEBUG
 Language     = English
 %1
 .
 MessageId    = 0x6
 Severity     = Error
-Facility     = OPENDS
+Facility     = OPENDJ
 SymbolicName = WIN_EVENT_ID_SERVER_STOPPED_OUTSIDE_SCM
 Language     = English
-OpenDS stopped outside the Service Control Manager.
-OpenDS is in %1.
+OpenDJ stopped outside the Service Control Manager.
+OpenDJ is in %1.
 .
diff --git a/opends/src/build-tools/windows/Makefile b/opends/src/build-tools/windows/Makefile
index 0493a62..6dc0df1 100644
--- a/opends/src/build-tools/windows/Makefile
+++ b/opends/src/build-tools/windows/Makefile
@@ -23,6 +23,7 @@
 #
 #
 #      Copyright 2008 Sun Microsystems, Inc.
+#      Portions Copyright 2011 ForgeRock AS
 
 #
 # This is the Makefile than can be used to generate the executables
@@ -43,7 +44,7 @@
 #
 
 CC=cl
-SERVICE_PROGNAME=opends_service.exe
+SERVICE_PROGNAME=opendj_service.exe
 LAUNCHER_ADMINISTRATOR_PROGNAME=launcher_administrator.exe
 WINLAUNCHER_PROGNAME=winlauncher.exe
 LINKER=link -nologo /machine:x86
@@ -67,7 +68,7 @@
 
 RES_FILE = EventLogMsg.res
 
-SERVICE_MANIFEST_FILE = opends_service.exe.manifest
+SERVICE_MANIFEST_FILE = opendj_service.exe.manifest
 LAUNCHER_ADMINISTRATOR_MANIFEST_FILE = launcher_administrator.exe.manifest
 
 .c.obj:
diff --git a/opends/src/build-tools/windows/opends_service.exe.manifest b/opends/src/build-tools/windows/opendj_service.exe.manifest
similarity index 91%
rename from opends/src/build-tools/windows/opends_service.exe.manifest
rename to opends/src/build-tools/windows/opendj_service.exe.manifest
index 20c4170..55d0c5f 100644
--- a/opends/src/build-tools/windows/opends_service.exe.manifest
+++ b/opends/src/build-tools/windows/opendj_service.exe.manifest
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
   <assemblyIdentity version="1.0.0.0"
-     processorArchitecture="X86" name="opends_service" type="win32"/> 
+     processorArchitecture="X86" name="opendj_service" type="win32"/> 
   <description>Executable used to run OpenDJ as a Windows Service</description>
   <!-- Identify the application security requirements. -->
   <ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
diff --git a/opends/src/build-tools/windows/service.c b/opends/src/build-tools/windows/service.c
index 7102901..fad6a83 100644
--- a/opends/src/build-tools/windows/service.c
+++ b/opends/src/build-tools/windows/service.c
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
+*      Portions Copyright 2011 ForgeRock AS
 */
 
 #include "service.h"
@@ -94,7 +95,7 @@
     reportOk = ReportEvent(
     _eventLog,              // event log handle
     eventType,              // info, warning, error
-    WIN_FACILITY_NAME_OPENDS,     // unique category for OPENDS
+    WIN_FACILITY_NAME_OPENDJ,     // unique category for OPENDJ
     eventId,
     NULL,               // no user security identifier
     argCount,             // number of args
@@ -109,7 +110,7 @@
     reportOk = ReportEvent(
     _eventLog,              // event log handle
     eventType,              // info, warning, error
-    WIN_FACILITY_NAME_OPENDS,     // unique category for OPENDS
+    WIN_FACILITY_NAME_OPENDJ,     // unique category for OPENDJ
     eventId,
     NULL,               // no user security identifier
     argCount,             // number of args
@@ -298,7 +299,7 @@
     }
   }
 
-  // Set the number of categories: 1 (OPENDS)
+  // Set the number of categories: 1 (OPENDJ)
   if (success)
   {
     long result = RegSetValueEx(
@@ -522,7 +523,7 @@
   BOOL createOk;
   BOOL waitOk;
 
-  debug("doStartApplication called");
+  debug("doStartApplication");
 
   if (strlen(relativePath)+strlen(_instanceDir)+1 < COMMAND_SIZE)
   {
@@ -538,11 +539,11 @@
       // startup is deleted (file logs\server.starting).
       const DWORD STARTDS_WAIT_DEFAULT_VALUE = 300000;
       DWORD wait = STARTDS_WAIT_DEFAULT_VALUE;
-      char * nWaitForStartDS = getenv("OPENDS_WINDOWS_SERVICE_STARTDS_WAIT");
+      char * nWaitForStartDS = getenv("OPENDJ_WINDOWS_SERVICE_STARTDS_WAIT");
       DWORD startDSExit;
       if (nWaitForStartDS != NULL)
       {
-        debug("doStartApplication: OPENDS_WINDOWS_SERVICE_STARTDS_WAIT env var set to %s",
+        debug("doStartApplication: OPENDJ_WINDOWS_SERVICE_STARTDS_WAIT env var set to %s",
             nWaitForStartDS);
         wait = (int)strtol(nWaitForStartDS, (char **)NULL, 10);
         if (wait <= 0)
@@ -552,7 +553,7 @@
       }
       else
       {
-        debug("doStartApplication: OPENDS_WINDOWS_SERVICE_STARTDS_WAIT is not set. Using default %d milliseconds.",
+        debug("doStartApplication: OPENDJ_WINDOWS_SERVICE_STARTDS_WAIT is not set. Using default %d milliseconds.",
             STARTDS_WAIT_DEFAULT_VALUE);
       }
       waitOk = waitForProcess(&procInfo, wait, &startDSExit);
@@ -594,11 +595,11 @@
       // Try to see if server is really running
       const DWORD DEFAULT_TRIES = 100;
       int nTries = DEFAULT_TRIES;
-      char * nTriesEnv = getenv("OPENDS_WINDOWS_SERVICE_START_NTRIES");
+      char * nTriesEnv = getenv("OPENDJ_WINDOWS_SERVICE_START_NTRIES");
       BOOL running = FALSE;
       if (nTriesEnv != NULL)
       {
-        debug("OPENDS_WINDOWS_SERVICE_START_NTRIES env var set to %s", nTriesEnv);
+        debug("OPENDJ_WINDOWS_SERVICE_START_NTRIES env var set to %s", nTriesEnv);
         nTries = (int)strtol(nTriesEnv, (char **)NULL, 10);
         if (nTries <= 0)
         {
@@ -607,7 +608,7 @@
       }
       else
       {
-        debug("OPENDS_WINDOWS_SERVICE_START_NTRIES is not set.  Using default %d tries.", nTries);
+        debug("OPENDJ_WINDOWS_SERVICE_START_NTRIES is not set.  Using default %d tries.", nTries);
       }	
 
       debug(
@@ -667,6 +668,8 @@
   // init out params
   char* relativePath = "\\bat\\stop-ds.bat";
   char command[COMMAND_SIZE];
+
+  debug("doStopApplication");
   if (strlen(relativePath)+strlen(_instanceDir)+1 < COMMAND_SIZE)
   {
     sprintf(command, "\"%s%s\" --windowsNetStop", _instanceDir, relativePath);
@@ -725,7 +728,7 @@
 // serviceBinPath  the path to the service binary.
 // instanceDir the instanceDirectory.
 // The string stored in serviceBinPath looks like
-// <SERVER_ROOT>/lib/opends_service.exe start <_instanceDir>
+// <SERVER_ROOT>/lib/opendj_service.exe start <_instanceDir>
 // It is up to the caller of the function to allocate
 // at least COMMAND_SIZE bytes in serviceBinPath.
 // The function returns SERVICE_RETURN_OK if we could create the binary
@@ -748,7 +751,7 @@
   {
     // failed to get the path of the executable file
     returnValue = SERVICE_RETURN_ERROR;
-    debug("Could not get the path of the executable file.");
+	debug("Could not get the path of the executable file.");
   }
   else
   {
@@ -978,7 +981,7 @@
 
   // __debugbreak();
 
-  debug("serviceMain called.");
+  debug("serviceMain");
 
   code = createServiceBinPath(cmdToRun);
 
@@ -1055,7 +1058,7 @@
       break;
 
       default:
-      debugError("doApplication() failed");
+      debugError("serviceMain: doStartApplication() failed");
       code = SERVICE_RETURN_ERROR;
       _serviceCurStatus = SERVICE_STOPPED;
       updateServiceStatus (
@@ -1089,7 +1092,7 @@
     BOOL updatedRunningStatus = FALSE;
 	DWORD returnValue;
     int refreshPeriodSeconds = 10;
-    char *refreshPeriodEnv = getenv("OPENDS_WINDOWS_SERVICE_REFRESH_PERIOD");
+    char *refreshPeriodEnv = getenv("OPENDJ_WINDOWS_SERVICE_REFRESH_PERIOD");
     if (refreshPeriodEnv != NULL)
     {
       refreshPeriodSeconds = (int)strtol(refreshPeriodEnv, (char **)NULL, 10);
@@ -1188,7 +1191,7 @@
       _serviceStatusHandle
      );
   }
-   debug("serviceMain() returning.");
+   debug("serviceMain returning.");
 }  // serviceMain
 
 
@@ -1269,7 +1272,7 @@
       {
         WORD argCount = 1;
         const char *argc[] = {_instanceDir};
-        debug("The server could not be stopped.");
+		debug("serviceHandler: The server could not be stopped.");
         // We could not stop the server
         reportLogEvent(
         EVENTLOG_ERROR_TYPE,
@@ -1329,7 +1332,7 @@
 
     break;
   }
-
+  debug("serviceHandler returning.");
 }  // serviceHandler
 
 // ---------------------------------------------------------------
@@ -1371,7 +1374,7 @@
 
   if (myService == NULL)
   {
-      debugError("Failed to open the service '%s'.", serviceName);
+	  debugError("getBinaryPathName: Failed to open the service '%s'.", serviceName);
   }
   else
   {
@@ -1399,7 +1402,7 @@
         }
         else
         {
-          debug("getBinaryPath: error calling QueryServiceConfig. Code [%d]",
+          debug("getBinaryPathName: error calling QueryServiceConfig. Code [%d]",
               errCode);
           break;
         }
@@ -1413,11 +1416,16 @@
         }
         else
         {
-          debug("getBinaryPath: the length of the binary path name is too big. serviceName='%s', binaryPath='%s'",
+          debug("getBinaryPathName: the length of the binary path name is too big. serviceName='%s', binaryPath='%s'",
               serviceName, serviceConfig->lpBinaryPathName);
         }
       }
     }
+    if (!CloseServiceHandle(myService))
+    {
+	  debug("getBinaryPathName: error closing handle of service. Code [%d]",
+	        GetLastError());
+    }
   }
 
   // free buffers
@@ -1635,9 +1643,9 @@
 } // serviceNameInUse
 
 // ---------------------------------------------------------------
-// Build a service name for OpenDS and make sure
+// Build a service name for OpenDJ and make sure
 // the service name is unique on the system. To achieve this requirement
-// the service name looks like <baseName> for the first OpenDS and
+// the service name looks like <baseName> for the first OpenDJ and
 // <baseName>-n if there are more than one.
 //
 // The functions returns SERVICE_RETURN_OK if we could create a service
@@ -1945,7 +1953,7 @@
 
 
 // ---------------------------------------------------------------
-// Function called to create a service for the OpenDS instance
+// Function called to create a service for the OpenDJ instance
 // where this executable is installed.
 // The first argument that is passed is the displayName of the service
 // and the second the description,
@@ -1973,7 +1981,7 @@
     {
       debug("Service '%s' already exists.", displayName);
       // There is a valid serviceName for the command to run, so
-      // OpenDS is registered as a service.
+      // OpenDJ is registered as a service.
       code = SERVICE_ALREADY_EXISTS;
       createRegistryKey(serviceName);
     }
@@ -2024,7 +2032,7 @@
 } // createService
 
 // ---------------------------------------------------------------
-// Function called to know if the OpenDS instance where this
+// Function called to know if the OpenDJ instance where this
 // executable is installed is running as a service or not.
 // Returns 0 if the instance is running as a service and print the
 // serviceName in the standard output.
@@ -2052,7 +2060,7 @@
     if (code == SERVICE_RETURN_OK)
     {
       // There is a valid serviceName for the command to run, so
-      // OpenDS is registered as a service.
+      // OpenDJ is registered as a service.
       fprintf(stdout, serviceName);
       returnCode = 0;
       debug("Service '%s' is enabled.", serviceName);
@@ -2086,7 +2094,7 @@
   int returnCode = 0;
   ServiceReturnCode code = serviceNameInUse(serviceName);
 
-  debug("Removing service.");
+  debug("Removing service with name %s.", serviceName);
 
   if (code != SERVICE_IN_USE)
   {
@@ -2119,7 +2127,7 @@
 } // removeServiceWithServiceName
 
 // ---------------------------------------------------------------
-// Function called to remove the service for the OpenDS instance
+// Function called to remove the service for the OpenDJ instance
 // where this executable is installed.
 // Returns 0 if the service was successfully removed.
 // Returns 1 if the service does not exist.
@@ -2134,7 +2142,7 @@
   char serviceName[MAX_SERVICE_NAME];
   ServiceReturnCode code;
 
-  debug("removeService()");
+  debug("removeService");
   code = createServiceBinPath(cmdToRun);
 
   if (code == SERVICE_RETURN_OK)
@@ -2154,7 +2162,7 @@
     returnCode = 2;
   }
 
-  debug("removeService() returning %d.", returnCode);
+  debug("removeService returning %d.", returnCode);
   return returnCode;
 } // removeService
 
@@ -2173,7 +2181,7 @@
   char cmdToRun[COMMAND_SIZE];
   ServiceReturnCode code;
 
-  debug("startService()");
+  debug("startService");
   code = createServiceBinPath(cmdToRun);
 
   if (code == SERVICE_RETURN_OK)
@@ -2229,7 +2237,7 @@
       WIN_EVENT_ID_SERVER_START_FAILED,
       argCount, argc
       );
-      debugError("For instance dir '%s', %s", argc[0], argc[1]);
+	  debugError("startService: For instance dir '%s', %s", argc[0], argc[1]);
     }
     deregisterEventLog();
   }
diff --git a/opends/src/server/org/opends/server/tools/ConfigureWindowsService.java b/opends/src/server/org/opends/server/tools/ConfigureWindowsService.java
index bb467db..424f248 100644
--- a/opends/src/server/org/opends/server/tools/ConfigureWindowsService.java
+++ b/opends/src/server/org/opends/server/tools/ConfigureWindowsService.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2008-2010 Sun Microsystems, Inc.
+ *      Portions Copyright 2011 ForgeRock AS 
  */
 
 package org.opends.server.tools;
@@ -54,8 +55,8 @@
 /**
   * This class is used to configure the Windows service for this instance on
   * this machine.
-  * This tool allows to enable and disable OpenDS to run as a Windows service
-  * and allows to know if OpenDS is running as a Windows service or not.
+  * This tool allows to enable and disable OpenDJ to run as a Windows service
+  * and allows to know if OpenDJ is running as a Windows service or not.
   *
   * Some comments about Vista:
   * In Vista, when we launch the subcommands that require administrator
@@ -168,8 +169,8 @@
 
   /**
    * Configures the Windows service for this instance on this machine.
-   * This tool allows to enable and disable OpenDS to run as a Windows service
-   * and allows to know if OpenDS is running as a Windows service or not.
+   * This tool allows to enable and disable OpenDJ to run as a Windows service
+   * and allows to know if OpenDJ is running as a Windows service or not.
    *
    * @param  args  The command-line arguments provided to this program.
    */
@@ -182,8 +183,8 @@
 
   /**
    * Configures the Windows service for this instance on this machine.
-   * This tool allows to enable and disable OpenDS to run as a Windows service
-   * and allows to know if OpenDS is running as a Windows service or not.
+   * This tool allows to enable and disable OpenDJ to run as a Windows service
+   * and allows to know if OpenDJ is running as a Windows service or not.
    *
    * @param  args  The command-line arguments provided to this program.
    * @param outStream the stream used to write the standard output.
@@ -341,9 +342,9 @@
   }
 
   /**
-   * Returns the service name associated with OpenDS or null if no service name
+   * Returns the service name associated with OpenDJ or null if no service name
    * could be found.
-   * @return the service name associated with OpenDS or null if no service name
+   * @return the service name associated with OpenDJ or null if no service name
    * could be found.
    */
   static String getServiceName()
@@ -391,7 +392,7 @@
   }
 
   /**
-   * Enables OpenDS to run as a windows service.
+   * Enables OpenDJ to run as a windows service.
    * @param out the stream used to write the standard output.
    * @param err the stream used to write the error output.
    * @return <CODE>SERVICE_ENABLE_SUCCESS</CODE>,
@@ -414,7 +415,7 @@
   }
 
   /**
-   * Enables OpenDS to run as a windows service.
+   * Enables OpenDJ to run as a windows service.
    * @param out the stream used to write the standard output.
    * @param err the stream used to write the error output.
    * @param serviceName the name of the service as it will appear in the
@@ -532,7 +533,7 @@
   }
 
   /**
-   * Disables OpenDS to run as a windows service.
+   * Disables OpenDJ to run as a windows service.
    * @param out the stream used to write the standard output.
    * @param err the stream used to write the error output.
    * @return <CODE>SERVICE_DISABLE_SUCCESS</CODE>,
@@ -690,7 +691,7 @@
   }
 
   /**
-    * Checks if OpenDS is enabled as a windows service and if it is
+    * Checks if OpenDJ is enabled as a windows service and if it is
     * write the serviceName in the output stream (if it is not null).
     * @param out the stream used to write the standard output.
     * @param err the stream used to write the error output.
@@ -832,7 +833,7 @@
   private static String getBinaryFullPath()
   {
     return SetupUtils.getScriptPath(
-        getServerRoot()+"\\lib\\opends_service.exe");
+        getServerRoot()+"\\lib\\opendj_service.exe");
   }
 
   /**

--
Gitblit v1.10.0