From 7a9ea4f564396dd7a57eff6180dba390d2de7d36 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 05 Feb 2008 17:26:11 +0000
Subject: [PATCH] Fix for issue 2902 (stop-ds -R restarts the server with client tool JVM)

---
 opends/resource/bin/stop-ds     |   16 ++++++++++++----
 opends/resource/bin/stop-ds.bat |   15 ++++++++++++---
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/opends/resource/bin/stop-ds b/opends/resource/bin/stop-ds
index 4fd2f01..126c33f 100755
--- a/opends/resource/bin/stop-ds
+++ b/opends/resource/bin/stop-ds
@@ -23,7 +23,7 @@
 # CDDL HEADER END
 #
 #
-#      Portions Copyright 2006-2007 Sun Microsystems, Inc.
+#      Portions Copyright 2006-2008 Sun Microsystems, Inc.
 
 
 # This script may be used to request that the Directory Server shut down.
@@ -49,8 +49,10 @@
 
 cd "${WORKING_DIR}"
 
-
-
+# We keep this values to reset the environment before calling start-ds.
+ORIGINAL_JAVA_ARGS=${OPENDS_JAVA_ARGS}
+ORIGINAL_JAVA_HOME=${OPENDS_JAVA_HOME}
+ORIGINAL_JAVA_BIN=${OPENDS_JAVA_BIN}
 
 
 # Specify the script name so that we can use the specified java properties.
@@ -68,7 +70,7 @@
 fi
 
 
-"${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
+"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
   org.opends.server.tools.StopDS --checkStoppability "${@}"
 EC=${?}
 
@@ -165,6 +167,12 @@
 then
   if test ${STOPPED} -eq 0
   then
+# Set the original values that the user had on the environment in order to be
+# sure that the start-ds script works with the proper arguments (in particular
+# if the user specified not to overwrite the environment).
+    OPENDS_JAVA_ARGS=${ORIGINAL_JAVA_ARGS}
+    OPENDS_JAVA_HOME=${ORIGINAL_JAVA_HOME}
+    OPENDS_JAVA_BIN=${ORIGINAL_JAVA_BIN}
     if test ${QUIET_MODE} -eq 0
     then
       "${INSTANCE_ROOT}/bin/start-ds" --quiet
diff --git a/opends/resource/bin/stop-ds.bat b/opends/resource/bin/stop-ds.bat
index b18a3a3..8107986 100644
--- a/opends/resource/bin/stop-ds.bat
+++ b/opends/resource/bin/stop-ds.bat
@@ -23,7 +23,7 @@
 rem CDDL HEADER END
 rem
 rem
-rem      Portions Copyright 2006-2007 Sun Microsystems, Inc.
+rem      Portions Copyright 2006-2008 Sun Microsystems, Inc.
 
 setlocal
 
@@ -33,6 +33,11 @@
 set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=stop-ds"
 for %%i in (%~sf0) do set DIR_HOME=%%~dPsi..
 
+rem We keep this values to reset the environment before calling start-ds.
+set ORIGINAL_JAVA_ARGS=%OPENDS_JAVA_ARGS%
+set ORIGINAL_JAVA_HOME=%OPENDS_JAVA_HOME%
+set ORIGINAL_JAVA_BIN=%OPENDS_JAVA_BIN%
+
 set INSTANCE_ROOT=%DIR_HOME%
 
 set LOG="%INSTANCE_ROOT%\logs\native-windows.out"
@@ -42,8 +47,6 @@
 rem echo %SCRIPT%: your-message-here >> %LOG%
 echo %SCRIPT%: invoked >> %LOG%
 
-set SCRIPT_NAME=start-ds
-
 rem Set environment variables
 set SCRIPT_UTIL_CMD=set-full-environment-and-test-java
 call "%INSTANCE_ROOT%\lib\_script-util.bat"
@@ -70,6 +73,12 @@
 
 :startUsingSystemCall
 echo %SCRIPT%: start using system call >> %LOG%
+rem Set the original values that the user had on the environment in order to be
+rem sure that the start-ds script works with the proper arguments (in particular
+rem if the user specified not to overwrite the environment).
+set OPENDS_JAVA_ARGS=%ORIGINAL_JAVA_ARGS%
+set OPENDS_JAVA_HOME=%ORIGINAL_JAVA_HOME%
+set OPENDS_JAVA_BIN=%ORIGINAL_JAVA_BIN%
 "%DIR_HOME%\bat\start-ds.bat"
 goto end
 

--
Gitblit v1.10.0