Skip to content

Commit

Permalink
Do major cleanup of Windows BAT files
Browse files Browse the repository at this point in the history
For ninja and midpoint itself. To be tested.
  • Loading branch information
mederly committed May 29, 2018
1 parent 5351f64 commit bec985f
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 198 deletions.
88 changes: 37 additions & 51 deletions dist/src/main/bin/midpoint.bat
Expand Up @@ -2,71 +2,57 @@

setlocal

set "BIN_DIR=%~dp0%~2"
if not "%MIDPOINT_HOME%" == "" goto gotHome
cd "%BIN_DIR%.."
mkdir var
cd var
mkdir log
cd "%BIN_DIR%.."
set "MIDPOINT_HOME=%cd%\var"
echo %MIDPOINT_HOME%
echo %BIN_DIR%
:gotHome

rem if script for start and stop exists
if exist "%BIN_DIR%\midpoint.bat" goto okBoot
echo %BIN_DIR%
echo The midpoint.bat file is not in \bin directory or is no accessible
goto end
:okBoot
set BIN_DIR=%~dp0
set LIB_DIR=%BIN_DIR%..\lib

if "%MIDPOINT_HOME%" == "" (
cd "%BIN_DIR%.."
if not exist var mkdir var
if not exist var\log mkdir var\log
set "MIDPOINT_HOME=%BIN_DIR%..\var"
)
echo Using MIDPOINT_HOME: "%MIDPOINT_HOME%"

rem if start/stop out file exists
if not "%BOOT_OUT%" == "" goto okOut
set "BOOT_OUT=%MIDPOINT_HOME%\log\midpoint.out"
echo %BOOT_OUT%
:okOut
if not exist "%BIN_DIR%midpoint.bat" (
echo Error: The midpoint.bat file is not in bin directory or is not accessible.
goto end
)

rem MIDPOINT_WAR if not defined
if exist "%cd%\lib\midpoint.war" goto gotWar
echo The midpoint.war is not in \lib directory
echo Can not start midPoint
goto end
:gotWar
if not exist "%LIB_DIR%\midpoint.war" (
echo Error: The midpoint.war is not in the lib directory
goto end
)

if "%MIDPOINT_HOME%" == "%MIDPOINT_HOME:;=%" goto homeNoSemicolon
echo Using MIDPOINT_HOME: "%MIDPOINT_HOME%"
echo Unable to start as MIDPOINT_HOME contains a semicolon (;) character
goto end
:homeNoSemicolon
if not "%MIDPOINT_HOME%" == "%MIDPOINT_HOME:;=%" (
echo Error: MIDPOINT_HOME contains a semicolon ";" character.
goto end
)

if "%BOOT_OUT%" == "" set BOOT_OUT=%MIDPOINT_HOME%\log\midpoint.out
echo Using BOOT_OUT: "%BOOT_OUT%"

rem ----- Execute The Requested Command ---------------------------------------

echo Using MIDPOINT_HOME: "%MIDPOINT_HOME%"

set _EXECJAVA=%_RUNJAVA%
set _NOHUP=nohup
set ACTION=start
if "%1" == "start" goto doStart
if "%1" == "stop" goto doStop

if ""%1"" == ""start"" goto doStart
if ""%1"" == ""stop"" goto doStop
echo Error: No command given. Specify either start or stop.
goto end

:doStart
shift
goto execStart

:doStop
shift
goto execStop
set RUN_JAVA=javaw
if not "%JAVA_HOME%" == "" set RUN_JAVA=%JAVA_HOME%\bin\javaw

:execStart
echo "%cd%\lib\midpoint.war"
start /b javaw -jar -Xms2048M -Xmx2048M -Dpython.cachedir="%MIDPOINT_HOME%\tmp" -Djavax.net.ssl.trustStore="%MIDPOINT_HOME%\keystore.jceks" -Djavax.net.ssl.trustStoreType=jceks -Dmidpoint.home="%MIDPOINT_HOME%" "%cd%\lib\midpoint.war" > "%BOOT_OUT%" 2>&1 &
echo Using RUN_JAVA: "%RUN_JAVA%"
echo Using JAVA_OPTS: "%JAVA_OPTS%"
echo Using parameters: "%*"
start /b %RUN_JAVA% -jar %JAVA_OPTS% -Xms2048M -Xmx2048M -Dpython.cachedir="%MIDPOINT_HOME%\tmp" -Djavax.net.ssl.trustStore="%MIDPOINT_HOME%\keystore.jceks" -Djavax.net.ssl.trustStoreType=jceks -Dmidpoint.home="%MIDPOINT_HOME%" "%LIB_DIR%\midpoint.war" %* > "%BOOT_OUT%" 2>&1
goto end

:execStop
echo "%cd%\lib\midpoint.war"
:doStop
shift
FOR /F "usebackq tokens=5" %%i IN (`netstat -aon ^| findstr "0.0.0.0:8080"`) DO taskkill /F /PID %%i
goto end

:end
85 changes: 47 additions & 38 deletions dist/src/main/bin/ninja.bat
Expand Up @@ -2,50 +2,59 @@

setlocal

set "BIN_DIR=%~dp0"

rem if script for execution is in bin directory
if exist "%BIN_DIR%\ninja.bat" goto okBoot
echo %BIN_DIR%
echo The keys.bat file is not in \bin
goto end
:okBoot

rem set midpoint.home
if not "%MIDPOINT_HOME%" == "" goto gotHome
cd "%BIN_DIR%.."
if exist "%BIN_DIR%..\var" goto setHome
echo %BIN_DIR%
echo ERROR: midpoint.home directory desn't exist
goto end
:setHome

set "MIDPOINT_HOME=%cd%\var"
echo %MIDPOINT_HOME%
echo %BIN_DIR%
:gotHome

rem NINJA_JAR if not defined
if exist "%cd%\lib\ninja.jar" goto gotJar
echo The ninja.jar is not in \lib directory
echo Can not start ninja
goto end
:gotJar

if "%MIDPOINT_HOME%" == "%MIDPOINT_HOME:;=%" goto homeNoSemicolon
set NINJA_JAR=ninja.jar

set BIN_DIR=%~dp0
set ROOT_DIR=%BIN_DIR%..
set VAR_DIR=%ROOT_DIR%\var
set NINJA_JAR_PATH=%ROOT_DIR%\lib\%NINJA_JAR%

set PARAMETERS=%*

set LOADER_PATH=
:argloop
IF NOT "%1"=="" (
IF "%1"=="-j" (
SET LOADER_PATH=-Dloader.path=%2
SHIFT
)
IF "%1"=="--jdbc" (
SET LOADER_PATH=-Dloader.path=%2
SHIFT
)
SHIFT
GOTO :argloop
)

if "%MIDPOINT_HOME%" == "" (
if not exist "%VAR_DIR%" (
echo Error: Default midpoint.home directory "%VAR_DIR%" does not exist.
goto end
)
set MIDPOINT_HOME=%VAR_DIR%
)

if not "%MIDPOINT_HOME%" == "%MIDPOINT_HOME:;=%" (
echo Error: Unable to start as MIDPOINT_HOME contains a semicolon ";" character
goto end
)

echo Using MIDPOINT_HOME: "%MIDPOINT_HOME%"
echo Unable to start as MIDPOINT_HOME contains a semicolon (;) character
goto end
:homeNoSemicolon

if not exist "%NINJA_JAR_PATH%" (
echo Error: %NINJA_JAR% is not in the lib directory.
echo Cannot start ninja
goto end
)

rem ----- Execute The Requested Command ---------------------------------------

echo Using MIDPOINT_HOME: "%MIDPOINT_HOME%"
set RUN_JAVA=java
if not "%JAVA_HOME%" == "" set RUN_JAVA=%JAVA_HOME%\bin\java

java -jar "%cd%\lib\ninja.jar" -m "%MIDPOINT_HOME%" %*
goto end
echo Using LOADER_PATH: "%LOADER_PATH%"
echo Using RUN_JAVA: "%RUN_JAVA%"

"%RUN_JAVA%" "%LOADER_PATH%" -jar "%NINJA_JAR_PATH%" -m "%MIDPOINT_HOME%" %PARAMETERS%

:end

85 changes: 47 additions & 38 deletions dist/src/main/bin/ninja37.bat
Expand Up @@ -2,50 +2,59 @@

setlocal

set "BIN_DIR=%~dp0"

rem if script for execution is in bin directory
if exist "%BIN_DIR%\ninja37.bat" goto okBoot
echo %BIN_DIR%
echo The keys.bat file is not in \bin
goto end
:okBoot

rem set midpoint.home
if not "%MIDPOINT_HOME%" == "" goto gotHome
cd "%BIN_DIR%.."
if exist "%BIN_DIR%..\var" goto setHome
echo %BIN_DIR%
echo ERROR: midpoint.home directory desn't exist
goto end
:setHome

set "MIDPOINT_HOME=%cd%\var"
echo %MIDPOINT_HOME%
echo %BIN_DIR%
:gotHome

rem NINJA_JAR if not defined
if exist "%cd%\lib\ninja-3.7.2-SNAPSHOT.jar" goto gotJar
echo The ninja-3.7.2-SNAPSHOT.jar is not in \lib directory
echo Can not start ninja
goto end
:gotJar

if "%MIDPOINT_HOME%" == "%MIDPOINT_HOME:;=%" goto homeNoSemicolon
set NINJA_JAR=ninja-3.7.2-SNAPSHOT.jar

set BIN_DIR=%~dp0
set ROOT_DIR=%BIN_DIR%..
set VAR_DIR=%ROOT_DIR%\var
set NINJA_JAR_PATH=%ROOT_DIR%\lib\%NINJA_JAR%

set PARAMETERS=%*

set LOADER_PATH=
:argloop
IF NOT "%1"=="" (
IF "%1"=="-j" (
SET LOADER_PATH=-Dloader.path=%2
SHIFT
)
IF "%1"=="--jdbc" (
SET LOADER_PATH=-Dloader.path=%2
SHIFT
)
SHIFT
GOTO :argloop
)

if "%MIDPOINT_HOME%" == "" (
if not exist "%VAR_DIR%" (
echo Error: Default midpoint.home directory "%VAR_DIR%" does not exist.
goto end
)
set MIDPOINT_HOME=%VAR_DIR%
)

if not "%MIDPOINT_HOME%" == "%MIDPOINT_HOME:;=%" (
echo Error: Unable to start as MIDPOINT_HOME contains a semicolon ";" character
goto end
)

echo Using MIDPOINT_HOME: "%MIDPOINT_HOME%"
echo Unable to start as MIDPOINT_HOME contains a semicolon (;) character
goto end
:homeNoSemicolon

if not exist "%NINJA_JAR_PATH%" (
echo Error: %NINJA_JAR% is not in the lib directory.
echo Cannot start ninja
goto end
)

rem ----- Execute The Requested Command ---------------------------------------

echo Using MIDPOINT_HOME: "%MIDPOINT_HOME%"
set RUN_JAVA=java
if not "%JAVA_HOME%" == "" set RUN_JAVA=%JAVA_HOME%\bin\java

java -jar "%cd%\lib\ninja-3.7.2-SNAPSHOT.jar" -m "%MIDPOINT_HOME%" %*
goto end
echo Using LOADER_PATH: "%LOADER_PATH%"
echo Using RUN_JAVA: "%RUN_JAVA%"

"%RUN_JAVA%" "%LOADER_PATH%" -jar "%NINJA_JAR_PATH%" -m "%MIDPOINT_HOME%" %PARAMETERS%

:end

43 changes: 8 additions & 35 deletions dist/src/main/bin/start.bat
Expand Up @@ -2,42 +2,15 @@

setlocal

set "BIN_DIR=%~dp0%~1"
if not "%MIDPOINT_HOME%" == "" goto gotHome
cd "%BIN_DIR%.."
mkdir var
cd var
mkdir log
cd "%BIN_DIR%.."
set "MIDPOINT_HOME=%cd%\var"
echo %MIDPOINT_HOME%
:gotHome
set "BIN_DIR=%~dp0"
set "EXECUTABLE=%BIN_DIR%midpoint.bat"

if exist "%BIN_DIR%\midpoint.bat" goto okHome
echo The MIDPOINT_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome
if not exist "%EXECUTABLE%" (
echo Error: Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end
)

set "EXECUTABLE=%BIN_DIR%\midpoint.bat"

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end
:okExec

rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" start %CMD_LINE_ARGS%
call "%EXECUTABLE%" start %*

:end

0 comments on commit bec985f

Please sign in to comment.