mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
22.41.2007 1faa6b83895dba3f275c72635f03518a6dc01007
Fix for Issues #1025 and #1248 ('stop-ds.bat should be able to stop server even if LDAP port' and 'cannot stop server through status panel').

The goal of these changes is to be able to have exactly the same user interface in Windows and Unix to stop the server. In windows we force the user to provide LDAP credentials even if the command is going to be run locally. The goal is to allow to stop the server using only system credentials (as we do in UNIX) when the user does not provide arguments when calling stop-ds.bat.

In order to do this I have written some native code. This native code is called when we start the server to:
1. Launch the java process and get the associated PID.
2. Create a server.pid file as we do for UNIX systems to store the PID of the process.

The native code that stops the server reads the PID file contents and tries to stop the process associated with the PID.

In order to allow the users to be able to build the product with independence of the platform, the binaries will be included with the source code. The code used to generate these binaries will also be provided.

I have generated 1 executable called winlauncher.exe. The binaries will be committed in the source tree under lib (with activation.jar and mail.jar). They will also be installed under <server root>\lib.

The native code is in the files winlauncher.c and winlauncher.h. These files are placed under the new directory build-tools/src/windows.

I have tried to keep the native code simple and leave as much logic as I could into the batch files (for instance everything related to the discovery of the java binaries) so that the administrators can play with them.

A README file has been also been included to explain how to generate the binaries.

Extras:
When we call start-ds from the command line, the server will not stop when the command prompt window is closed (unless start-ds was called to run in not-detached mode). The next step is to register DS as a service to avoid the server to be stopped when the user logs out.

When we call setup (with no arguments) or the statuspanel the generated process (and windows) will no longer get killed when the command prompt window is killed.

When the user double-clicks on the setup.bat or the statuspanel.bat files, the command prompt window only appears briefly. Today when we do this a command prompt window stays open until we close setup or the status panel window.
5 files modified
85 ■■■■ changed files
opends/resource/bin/start-ds.bat 4 ●●●● patch | view | raw | blame | history
opends/resource/bin/statuspanel.bat 39 ●●●● patch | view | raw | blame | history
opends/resource/bin/stop-ds.bat 14 ●●●●● patch | view | raw | blame | history
opends/resource/setup.bat 14 ●●●● patch | view | raw | blame | history
opends/resource/uninstall.bat 14 ●●●● patch | view | raw | blame | history
opends/resource/bin/start-ds.bat
@@ -23,7 +23,7 @@
rem CDDL HEADER END
rem
rem
rem      Portions Copyright 2006 Sun Microsystems, Inc.
rem      Portions Copyright 2006-2007 Sun Microsystems, Inc.
setlocal
@@ -76,7 +76,7 @@
:runDetach
if not exist "%DIR_HOME%\logs\server.out" echo. > "%DIR_HOME%\logs\server.out"
if not exist "%DIR_HOME%\logs\server.starting" echo. > "%DIR_HOME%\logs\server.starting"
start "OpenDS %DIR_HOME%" /B "%JAVA_BIN%" %JAVA_ARGS% org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
"%DIR_HOME%\lib\winlauncher.exe" start "%DIR_HOME%" "%JAVA_BIN%" %JAVA_ARGS%  org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
"%JAVA_BIN%" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete --targetFile "%DIR_HOME%\logs\server.starting" --logFile "%DIR_HOME%\logs\server.out"
goto end
opends/resource/bin/statuspanel.bat
@@ -23,10 +23,41 @@
rem CDDL HEADER END
rem
rem
rem      Portions Copyright 2007 Sun Microsystems, Inc.
rem      Portions Copyright 2006-2007 Sun Microsystems, Inc.
setlocal
set OPENDS_INVOKE_CLASS="org.opends.statuspanel.StatusPanelLauncher"
set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=statuspanel"
call "%~dP0\_server-script.bat" %*
set DIR_HOME=%~dP0..
set INSTANCE_ROOT=%DIR_HOME%
:checkJavaBin
if "%JAVA_BIN%" == "" goto noJavaBin
goto setClassPath
:noJavaBin
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
set JAVA_BIN=%JAVA_HOME%\bin\java.exe
goto setClassPath
:noJavaHome
if not exist "%DIR_HOME%\bin\set-java-home.bat" goto noSetJavaHome
call "%DIR_HOME%\bin\set-java-home.bat"
set JAVA_BIN=%JAVA_HOME%\bin\java.exe
goto setClassPath
:noSetJavaHome
echo Error: JAVA_HOME environment variable is not set.
echo        Please set it to a valid Java 5 installation.
goto end
:setClassPath
FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\bin\setcp.bat" %%x
set PATH=%SystemRoot%
"%DIR_HOME%\lib\winlauncher.exe" launch "%DIR_HOME%" "%JAVA_BIN%" %JAVA_ARGS%  org.opends.statuspanel.StatusPanelLauncher %*
goto end
:end
opends/resource/bin/stop-ds.bat
@@ -23,10 +23,22 @@
rem CDDL HEADER END
rem
rem
rem      Portions Copyright 2006 Sun Microsystems, Inc.
rem      Portions Copyright 2006-2007 Sun Microsystems, Inc.
setlocal
set OPENDS_INVOKE_CLASS="org.opends.server.tools.StopDS"
set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=stop-ds"
set DIR_HOME=%~dP0..
set ARGUMENTS=1
if "%*" == "" set ARGUMENTS=0
if "%ARGUMENTS%" == "1" goto stopWithLDAP
if not exist "%DIR_HOME%\logs\server.pid" goto stopWithLDAP
"%DIR_HOME%\lib\winlauncher.exe" stop "%DIR_HOME%"
goto end
:stopWithLDAP
call "%~dP0\_client-script.bat" %*
:end
opends/resource/setup.bat
@@ -23,11 +23,11 @@
rem CDDL HEADER END
rem
rem
rem      Portions Copyright 2006 Sun Microsystems, Inc.
rem      Portions Copyright 2006-2007 Sun Microsystems, Inc.
setlocal
set DIR_HOME=%~dP0
set DIR_HOME=%~dP0.
set INSTANCE_ROOT=%DIR_HOME%
:checkJavaBin
@@ -57,8 +57,16 @@
set PATH=%SystemRoot%
"%JAVA_BIN%" %JAVA_ARGS% org.opends.quicksetup.installer.InstallLauncher -P setup.bat %*
if "%*" == "" goto callLaunch
goto callJava
:callLaunch
"%DIR_HOME%\lib\winlauncher.exe" launch "%DIR_HOME%" "%JAVA_BIN%" %JAVA_ARGS% org.opends.quicksetup.installer.InstallLauncher -P setup.bat
goto end
:callJava
"%JAVA_BIN%" %JAVA_ARGS% org.opends.quicksetup.installer.InstallLauncher -P setup.bat %*
goto end
:end
opends/resource/uninstall.bat
@@ -23,11 +23,11 @@
rem CDDL HEADER END
rem
rem
rem      Portions Copyright 2006 Sun Microsystems, Inc.
rem      Portions Copyright 2006-2007 Sun Microsystems, Inc.
setlocal
set DIR_HOME=%~dP0
set DIR_HOME=%~dP0.
set INSTANCE_ROOT=%DIR_HOME%
:checkJavaBin
@@ -57,7 +57,15 @@
set PATH=%SystemRoot%
"%JAVA_BIN%" %JAVA_ARGS% org.opends.quicksetup.uninstaller.UninstallLauncher %*
if "%*" == "" goto callLaunch
goto callJava
:callLaunch
"%DIR_HOME%\lib\winlauncher.exe" launch "%DIR_HOME%" "%JAVA_BIN%" %JAVA_ARGS% org.opends.quicksetup.uninstaller.UninstallLauncher
goto end
:callJava
"%JAVA_BIN%" %JAVA_ARGS% org.opends.quicksetup.uninstaller.UninstallLauncher %*
goto end
:end