From 4c484ff6ea57ce79c5072a830e6536ac41c820c3 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Thu, 15 Mar 2007 15:52:50 +0000
Subject: [PATCH] Fix for issue 528 (Windows Service Definition for Automatic Startup).

---
 opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java b/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java
index 5399c19..86b1314 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java
@@ -177,6 +177,7 @@
     BooleanArgument   showUsage;
     BooleanArgument   silentInstall;
     BooleanArgument   skipPortCheck;
+    BooleanArgument   noWindowsService;
     FileBasedArgument rootPWFile;
     IntegerArgument   ldapPort;
     IntegerArgument   jmxPort;
@@ -278,6 +279,14 @@
                             null, null, MSGID_INSTALLDS_DESCRIPTION_ROOTPWFILE);
       argParser.addArgument(rootPWFile);
 
+      noWindowsService = new BooleanArgument("nowindowsservice", 'n',
+                                "noWindowsService",
+                                MSGID_INSTALLDS_DESCRIPTION_NO_WINDOWS_SERVICE);
+      if (SetupUtils.isWindows())
+      {
+        argParser.addArgument(noWindowsService);
+      }
+
       showUsage = new BooleanArgument("help", 'H', "help",
                                       MSGID_INSTALLDS_DESCRIPTION_HELP);
       argParser.addArgument(showUsage);
@@ -790,6 +799,24 @@
       }
     }
 
+    boolean enableService = false;
+    // If we are in Windows ask if the server must run as a windows service.
+    if (SetupUtils.isWindows())
+    {
+      if (silentInstall.isPresent())
+      {
+        enableService = !noWindowsService.isPresent();
+      }
+      else if (noWindowsService.isPresent())
+      {
+        enableService = false;
+      }
+      else
+      {
+        String message = getMessage(MSGID_INSTALLDS_PROMPT_ENABLE_SERVICE);
+        enableService = promptForBoolean(message, Boolean.TRUE);
+      }
+    }
 
     // At this point, we should be able to invoke the ConfigureDS utility to
     // apply the requested configuration.
@@ -976,6 +1003,24 @@
       SetupUtils.writeSetJavaHome(serverRoot);
     } catch (Exception e) {}
 
+    if (enableService)
+    {
+      String message = getMessage(MSGID_INSTALLDS_ENABLING_WINDOWS_SERVICE);
+      System.out.println(wrapText(message, MAX_LINE_WIDTH));
+      int code = ConfigureWindowsService.enableService(System.out,
+          System.err);
+
+      switch (code)
+      {
+      case ConfigureWindowsService.SERVICE_ENABLE_SUCCESS:
+        break;
+      case ConfigureWindowsService.SERVICE_ALREADY_ENABLED:
+        break;
+      default:
+        // It did not work.
+        return code;
+      }
+    }
 
     // If we've gotten here, then everything seems to have gone smoothly.
     if (! silentInstall.isPresent())

--
Gitblit v1.10.0