From 9e7e37076fc9cc06d488a61b91fa1133b4c46754 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 27 Oct 2014 17:22:43 +0200 Subject: [PATCH] Introduce elasticsearch.in.bat (i.e. es.in for Windows) Break-out common functionality between elasticsearch.bat and service.bat Relates #8237 (cherry picked from commit 87095e79534bcef97b2b275322c924bd96b34e3b) --- bin/elasticsearch.bat | 78 +--------------------------- bin/elasticsearch.in.bat | 83 ++++++++++++++++++++++++++++++ bin/service.bat | 42 ++------------- src/main/assemblies/common-bin.xml | 1 + 4 files changed, 91 insertions(+), 113 deletions(-) create mode 100644 bin/elasticsearch.in.bat diff --git a/bin/elasticsearch.bat b/bin/elasticsearch.bat index 0784f84fae6..b6da883d6fa 100644 --- a/bin/elasticsearch.bat +++ b/bin/elasticsearch.bat @@ -1,84 +1,10 @@ @echo off SETLOCAL - -if NOT DEFINED JAVA_HOME goto err - -set SCRIPT_DIR=%~dp0 -for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI - - -REM ***** JAVA options ***** - -if "%ES_MIN_MEM%" == "" ( -set ES_MIN_MEM=256m -) - -if "%ES_MAX_MEM%" == "" ( -set ES_MAX_MEM=1g -) - -if NOT "%ES_HEAP_SIZE%" == "" ( -set ES_MIN_MEM=%ES_HEAP_SIZE% -set ES_MAX_MEM=%ES_HEAP_SIZE% -) - -set JAVA_OPTS=%JAVA_OPTS% -Xms%ES_MIN_MEM% -Xmx%ES_MAX_MEM% - -if NOT "%ES_HEAP_NEWSIZE%" == "" ( -set JAVA_OPTS=%JAVA_OPTS% -Xmn%ES_HEAP_NEWSIZE% -) - -if NOT "%ES_DIRECT_SIZE%" == "" ( -set JAVA_OPTS=%JAVA_OPTS% -XX:MaxDirectMemorySize=%ES_DIRECT_SIZE% -) - -set JAVA_OPTS=%JAVA_OPTS% -Xss256k - -REM Enable aggressive optimizations in the JVM -REM - Disabled by default as it might cause the JVM to crash -REM set JAVA_OPTS=%JAVA_OPTS% -XX:+AggressiveOpts - -set JAVA_OPTS=%JAVA_OPTS% -XX:+UseParNewGC -set JAVA_OPTS=%JAVA_OPTS% -XX:+UseConcMarkSweepGC - -set JAVA_OPTS=%JAVA_OPTS% -XX:CMSInitiatingOccupancyFraction=75 -set JAVA_OPTS=%JAVA_OPTS% -XX:+UseCMSInitiatingOccupancyOnly - -REM When running under Java 7 -REM JAVA_OPTS=%JAVA_OPTS% -XX:+UseCondCardMark - -REM GC logging options -- uncomment to enable -REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCDetails -REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCTimeStamps -REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintClassHistogram -REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintTenuringDistribution -REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCApplicationStoppedTime -REM JAVA_OPTS=%JAVA_OPTS% -Xloggc:/var/log/elasticsearch/gc.log - -REM Causes the JVM to dump its heap on OutOfMemory. -set JAVA_OPTS=%JAVA_OPTS% -XX:+HeapDumpOnOutOfMemoryError -REM The path to the heap dump location, note directory must exists and have enough -REM space for a full heap dump. -REM JAVA_OPTS=%JAVA_OPTS% -XX:HeapDumpPath=$ES_HOME/logs/heapdump.hprof - -REM Disables explicit GC -set JAVA_OPTS=%JAVA_OPTS% -XX:+DisableExplicitGC - -set ES_CLASSPATH=%ES_CLASSPATH%;%ES_HOME%/lib/${project.build.finalName}.jar;%ES_HOME%/lib/*;%ES_HOME%/lib/sigar/* -set ES_PARAMS=-Delasticsearch -Des-foreground=yes -Des.path.home="%ES_HOME%" - TITLE Elasticsearch ${project.version} +CALL %~dp0elasticsearch.in.bat + "%JAVA_HOME%\bin\java" %JAVA_OPTS% %ES_JAVA_OPTS% %ES_PARAMS% %* -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" -goto finally - - -:err -echo JAVA_HOME environment variable must be set! -pause - - -:finally ENDLOCAL diff --git a/bin/elasticsearch.in.bat b/bin/elasticsearch.in.bat new file mode 100644 index 00000000000..2b8faa6a264 --- /dev/null +++ b/bin/elasticsearch.in.bat @@ -0,0 +1,83 @@ +@echo off + +if DEFINED JAVA_HOME goto cont + +:err +echo JAVA_HOME environment variable must be set! +pause +exit + +:cont +set SCRIPT_DIR=%~dp0 +for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI + + +REM ***** JAVA options ***** + +if "%ES_MIN_MEM%" == "" ( +set ES_MIN_MEM=256m +) + +if "%ES_MAX_MEM%" == "" ( +set ES_MAX_MEM=1g +) + +if NOT "%ES_HEAP_SIZE%" == "" ( +set ES_MIN_MEM=%ES_HEAP_SIZE% +set ES_MAX_MEM=%ES_HEAP_SIZE% +) + +REM min and max heap sizes should be set to the same value to avoid +REM stop-the-world GC pauses during resize, and so that we can lock the +REM heap in memory on startup to prevent any of it from being swapped +REM out. +set JAVA_OPTS=%JAVA_OPTS% -Xms%ES_MIN_MEM% -Xmx%ES_MAX_MEM% + +REM new generation +if NOT "%ES_HEAP_NEWSIZE%" == "" ( +set JAVA_OPTS=%JAVA_OPTS% -Xmn%ES_HEAP_NEWSIZE% +) + +REM max direct memory +if NOT "%ES_DIRECT_SIZE%" == "" ( +set JAVA_OPTS=%JAVA_OPTS% -XX:MaxDirectMemorySize=%ES_DIRECT_SIZE% +) + +REM reduce the per-thread stack size +set JAVA_OPTS=%JAVA_OPTS% -Xss256k + +REM set to headless, just in case +set JAVA_OPTS=%JAVA_OPTS% -Djava.awt.headless=true + +REM Force the JVM to use IPv4 stack +if NOT "%ES_USE_IPV4%" == "" ( +set JAVA_OPTS=%JAVA_OPTS% -Djava.net.preferIPv4Stack=true +) + +set JAVA_OPTS=%JAVA_OPTS% -XX:+UseParNewGC +set JAVA_OPTS=%JAVA_OPTS% -XX:+UseConcMarkSweepGC + +set JAVA_OPTS=%JAVA_OPTS% -XX:CMSInitiatingOccupancyFraction=75 +set JAVA_OPTS=%JAVA_OPTS% -XX:+UseCMSInitiatingOccupancyOnly + +REM When running under Java 7 +REM JAVA_OPTS=%JAVA_OPTS% -XX:+UseCondCardMark + +if NOT "%ES_USE_GC_LOGGING%" == "" set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCDetails +if NOT "%ES_USE_GC_LOGGING%" == "" set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCTimeStamps +if NOT "%ES_USE_GC_LOGGING%" == "" set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintClassHistogram +if NOT "%ES_USE_GC_LOGGING%" == "" set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintTenuringDistribution +if NOT "%ES_USE_GC_LOGGING%" == "" set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCApplicationStoppedTime +if NOT "%ES_USE_GC_LOGGING%" == "" set JAVA_OPTS=%JAVA_OPTS% -Xloggc:%ES_HOME%/logs/gc.log + +REM Causes the JVM to dump its heap on OutOfMemory. +set JAVA_OPTS=%JAVA_OPTS% -XX:+HeapDumpOnOutOfMemoryError +REM The path to the heap dump location, note directory must exists and have enough +REM space for a full heap dump. +REM JAVA_OPTS=%JAVA_OPTS% -XX:HeapDumpPath=$ES_HOME/logs/heapdump.hprof + +REM Disables explicit GC +set JAVA_OPTS=%JAVA_OPTS% -XX:+DisableExplicitGC + +set ES_CLASSPATH=%ES_CLASSPATH%;%ES_HOME%/lib/${project.build.finalName}.jar;%ES_HOME%/lib/*;%ES_HOME%/lib/sigar/* +set ES_PARAMS=-Delasticsearch -Des-foreground=yes -Des.path.home="%ES_HOME%" \ No newline at end of file diff --git a/bin/service.bat b/bin/service.bat index 294bd107174..72062b99b7d 100644 --- a/bin/service.bat +++ b/bin/service.bat @@ -1,6 +1,8 @@ @echo off SETLOCAL +TITLE Elasticsearch Service ${project.version} + if NOT DEFINED JAVA_HOME goto err set SCRIPT_DIR=%~dp0 @@ -43,8 +45,6 @@ set SERVICE_ID=%1 if "%LOG_OPTS%" == "" set LOG_OPTS=--LogPath "%LOG_DIR%" --LogPrefix "%SERVICE_ID%" --StdError auto --StdOutput auto -TITLE Elasticsearch Service ${project.version} - if /i %SERVICE_CMD% == install goto doInstall if /i %SERVICE_CMD% == remove goto doRemove if /i %SERVICE_CMD% == start goto doStart @@ -127,44 +127,14 @@ if NOT "%ES_HEAP_SIZE%" == "" set ES_MAX_MEM=%ES_HEAP_SIZE% call:convertxm %ES_MIN_MEM% JVM_XMS call:convertxm %ES_MAX_MEM% JVM_XMX -rem java_opts might be empty - init to avoid tripping commons daemon (if the command starts with ;) -if not "%JAVA_OPTS%" == "" set JAVA_OPTS=%JAVA_OPTS% -XX:+UseParNewGC +REM java_opts might be empty - init to avoid tripping commons daemon (if the command starts with ;) if "%JAVA_OPTS%" == "" set JAVA_OPTS=-XX:+UseParNewGC -if NOT "%ES_HEAP_NEWSIZE%" == "" set JAVA_OPTS=%JAVA_OPTS% -Xmn%ES_HEAP_NEWSIZE% - -if NOT "%ES_DIRECT_SIZE%" == "" set JAVA_OPTS=%JAVA_OPTS% -XX:MaxDirectMemorySize=%ES_DIRECT_SIZE% +CALL %ES_HOME%\bin\elasticsearch.in.bat rem thread stack size set JVM_SS=256 -REM Enable aggressive optimizations in the JVM -REM - Disabled by default as it might cause the JVM to crash -REM set JAVA_OPTS=%JAVA_OPTS% -XX:+AggressiveOpts - - -set JAVA_OPTS=%JAVA_OPTS% -XX:+UseConcMarkSweepGC - -set JAVA_OPTS=%JAVA_OPTS% -XX:CMSInitiatingOccupancyFraction=75 -set JAVA_OPTS=%JAVA_OPTS% -XX:+UseCMSInitiatingOccupancyOnly - -REM GC logging options -- uncomment to enable -REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCDetails -REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCTimeStamps -REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintClassHistogram -REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintTenuringDistribution -REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCApplicationStoppedTime -REM JAVA_OPTS=%JAVA_OPTS% -Xloggc:/var/log/elasticsearch/gc.log - -REM Causes the JVM to dump its heap on OutOfMemory. -set JAVA_OPTS=%JAVA_OPTS% -XX:+HeapDumpOnOutOfMemoryError -REM The path to the heap dump location, note directory must exists and have enough -REM space for a full heap dump. -REM JAVA_OPTS=%JAVA_OPTS% -XX:HeapDumpPath=$ES_HOME/logs/heapdump.hprof - -REM Disables explicit GC -set JAVA_OPTS=%JAVA_OPTS% -XX:+DisableExplicitGC - if "%DATA_DIR%" == "" set DATA_DIR=%ES_HOME%\data if "%WORK_DIR%" == "" set WORK_DIR=%ES_HOME% @@ -173,7 +143,6 @@ if "%CONF_DIR%" == "" set CONF_DIR=%ES_HOME%\config if "%CONF_FILE%" == "" set CONF_FILE=%ES_HOME%\config\elasticsearch.yml -set ES_CLASSPATH=%ES_CLASSPATH%;%ES_HOME%/lib/elasticsearch-%ES_VERSION%.jar;%ES_HOME%/lib/*;%ES_HOME%/lib/sigar/* set ES_PARAMS=-Delasticsearch;-Des.path.home="%ES_HOME%";-Des.default.config="%CONF_FILE%";-Des.default.path.home="%ES_HOME%";-Des.default.path.logs="%LOG_DIR%";-Des.default.path.data="%DATA_DIR%";-Des.default.path.work="%WORK_DIR%";-Des.default.path.conf="%CONF_DIR%" set JVM_OPTS=%JAVA_OPTS: =;% @@ -198,7 +167,6 @@ goto:eof :err echo JAVA_HOME environment variable must be set! pause - goto:eof rem --- @@ -233,4 +201,4 @@ set /a conv=%conv% * 1024 set "%~2=%conv%" goto:eof -ENDLOCAL +ENDLOCAL \ No newline at end of file diff --git a/src/main/assemblies/common-bin.xml b/src/main/assemblies/common-bin.xml index 46b5631fb43..eeff9f28808 100644 --- a/src/main/assemblies/common-bin.xml +++ b/src/main/assemblies/common-bin.xml @@ -34,6 +34,7 @@ bin dos + elasticsearch.in.bat elasticsearch.bat plugin.bat service.bat