Created
July 18, 2019 22:37
-
-
Save Giwi/5272fc8aeaebe4322f25aafcf22bbdf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
@rem set JAVA_HOME=/opt/java8 | |
@rem set WARP10_HOME=D:\Warp10\warp10-2.1.0 | |
set /a JMX_PORT=1098 | |
@rem Find java.exe | |
if defined JAVA_HOME goto findJavaFromJavaHome | |
set JAVA_EXE=java.exe | |
%JAVA_EXE% -version >NUL 2>&1 | |
echo. | |
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | |
echo. | |
echo Please set the JAVA_HOME variable in your environment to match the | |
echo location of your Java installation. | |
goto fail | |
@rem TODO check java version | |
:findJavaFromJavaHome | |
set JAVA_HOME=%JAVA_HOME:"=% | |
set JAVA_EXE=%JAVA_HOME%/bin/java.exe | |
if exist "%JAVA_EXE%" goto init | |
echo. | |
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% | |
echo. | |
echo Please set the JAVA_HOME variable in your environment to match the | |
echo location of your Java installation. | |
goto fail | |
set CMD_LINE_ARGS=%* | |
:fail | |
exit /b 1 | |
:init | |
if not defined WARP10_HOME set WARP10_HOME=%CD%\.. | |
if not defined WARP10_DATA_DIR set WARP10_DATA_DIR=%WARP10_HOME% | |
set WARP10_REVISION=2.1.0 | |
set WARP10_CONFIG_DIR=%WARP10_HOME%\etc\conf.d | |
set WARP10_SECRETS=%WARP10_CONFIG_DIR%\00-secrets.conf | |
set WARP10_JAR=%WARP10_HOME%\bin\warp10-%WARP10_REVISION%.jar | |
set WARP10_CLASS=io.warp10.standalone.Warp | |
set WARP10_INIT=io.warp10.standalone.WarpInit | |
:: The lib directory is dedicated to user libraries except of UDF(jars directory): extensions;.. | |
set WARP10_CP=%WARP10_HOME%\etc:%WARP10_JAR%:%WARP10_HOME%\lib/* | |
set WARP10_HEAP=1g | |
set WARP10_HEAP_MAX=1g | |
set LEVELDB_HOME=%WARP10_DATA_DIR%\leveldb | |
set SENSISION_EVENTS_DIR=%WARP10_DATA_DIR%\sensision\metrics | |
set LOG4J_CONF=%WARP10_HOME%\etc\log4j.properties | |
set JAVA_HEAP_DUMP=%WARP10_HOME%\logs\java.heapdump | |
:: you can specialize your metrics for this instance of Warp10 | |
@rem SENSISION_DEFAULT_LABELS=-Dsensision.default.labels=instance=warp10-test,env=dev | |
set JAVA_OPTS=-Djava.awt.headless=true -Dlog4j.configuration=file:%LOG4J_CONF% -Dsensision.server.port=0 %SENSISION_DEFAULT_LABELS% -Dsensision.events.dir=%SENSISION_EVENTS_DIR% -Xms%WARP10_HEAP% -Xmx%WARP10_HEAP_MAX% -XX:+UseG1GC | |
set MALLOC_ARENA_MAX=1 | |
:: Sed suffix allows compatibility between Linux and MacOS | |
set SED_SUFFIX=.bak | |
set "CONFIG_FILES=" | |
if "%1" == "bootstrap" goto bootstrap | |
:: | |
:: getConfigFiles | |
:: | |
:getConfigFiles | |
for %%x in ("%WARP10_CONFIG_DIR%\*.conf") do set CONFIG_FILES=!CONFIG_FILES! %%x | |
if defined CONFIG_FILES set CONFIG_FILES=%CONFIG_FILES:~15% | |
goto :eof | |
:: | |
:: moveDir dir | |
:: | |
:moveDir | |
move /Y %WARP10_HOME%\%1 %WARP10_DATA_DIR%\%1 >NUL | |
goto :eof | |
:: | |
:: replace oldStr newStr file | |
:: | |
:replace | |
setlocal enableextensions disabledelayedexpansion | |
set "search=%1" | |
set "replace=%2" | |
for /f "delims=" %%i in ('type "%3" ^& break ^> "%3" ') do ( | |
set "line=%%i" | |
setlocal enabledelayedexpansion | |
>>"%3" echo(!line:%search%=%replace%! | |
endlocal | |
) | |
goto :eof | |
:innerFindReplace | |
@echo off | |
REM -- Prepare the Command Processor -- | |
SETLOCAL ENABLEEXTENSIONS | |
SETLOCAL DISABLEDELAYEDEXPANSION | |
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF | |
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do ( | |
set "line=%%B" | |
if defined line ( | |
call set "line=echo.%%line:%~1=%~2%%" | |
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X | |
) ELSE echo. | |
) | |
goto :eof | |
:findReplace | |
call :innerFindReplace %1 %2 %3 > "%3.new" | |
move /Y "%3.new" "%3" >NUL | |
goto :eof | |
:: bootstrap | |
:bootstrap | |
echo "Bootstrap.." | |
call :getConfigFiles | |
if defined CONFIG_FILES ( | |
echo "Config file already exists - Abort bootstrap... %CONFIG_FILES%" | |
goto fail | |
) | |
:: | |
:: %WARP10_HOME% != %WARP10_DATA_DIR% | |
:: A dedicated data directory has been provided | |
:: Move data to %WARP10_DATA_DIR%\etc, %WARP10_DATA_DIR%\logs, %WARP10_DATA_DIR%\leveldb.. | |
:: | |
if not "%WARP10_DATA_DIR%" == "%WARP10_HOME%" ( | |
echo " WARP10_DATA_DIR: %WARP10_DATA_DIR%" | |
if not exist "%WARP10_DATA_DIR%" ( | |
echo "%WARP10_DATA_DIR% does not exist - Creating it..." | |
setlocal enableextensions | |
md "%WARP10_DATA_DIR%" | |
endlocal | |
) | |
call :moveDir "logs" | |
call :moveDir "etc" | |
call :moveDir "leveldb" | |
call :moveDir "datalog" | |
call :moveDir "datalog_done" | |
call :moveDir "macros" | |
call :moveDir "jars" | |
call :moveDir "lib" | |
call :moveDir "warpscripts" | |
) | |
:: Copy the template configuration file | |
for /r "%WARP10_HOME%\conf.templates\standalone" %%i in ("*.template") do ( | |
copy /Y "%%i" "%WARP10_CONFIG_DIR%\%%~ni" >NUL | |
call :findReplace "/opt/warp10-2.1.0" "%WARP10_HOME%" "%WARP10_CONFIG_DIR%\%%~ni" | |
call :replace "/" "\" "%WARP10_CONFIG_DIR%\%%~ni" | |
) | |
goto fail | |
call :replace " WARP10_HOME=/opt/warp10-2.1.0" " WARP10_HOME=%WARP10_HOME%" %WARP10_HOME%\bin\snapshot.bat | |
call :replace " LEVELDB_HOME=${WARP10_HOME}/leveldb" " LEVELDB_HOME=%LEVELDB_HOME%" %WARP10_HOME%\bin\snapshot.bat | |
call :replace "log4j.appender.warpLog.File=/opt/warp10-2.1.0/logs/nohup.out" "log4j.appender.warpLog.File=%WARP10_HOME%\logs\nohup.out" %WARP10_HOME%\etc\log4j.properties | |
call :replace "log4j.appender.warpscriptLog.File=/opt/warp10-2.1.0/logs/warpscript.out" "log4j.appender.warpscriptLog.File=%WARP10_HOME%\logs\warpscript.out" %WARP10_HOME%\etc\log4j.properties | |
:: Generate secrets | |
python %WARP10_HOME%/etc/generate_crypto_key.py %WARP10_SECRETS% | |
call :getConfigFiles | |
:: Edit the warp10-tokengen.mc2 to use or not the secret | |
"%JAVA_EXE%" -cp "%WARP10_CP%" io.warp10.WarpConfig %CONFIG_FILES% token.secret | |
goto :eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment