2013-09-16 05:57:55 -04:00
|
|
|
@echo off
|
|
|
|
SETLOCAL
|
|
|
|
|
2014-10-27 11:22:43 -04:00
|
|
|
TITLE Elasticsearch Service ${project.version}
|
|
|
|
|
2013-09-16 05:57:55 -04:00
|
|
|
if NOT DEFINED JAVA_HOME goto err
|
|
|
|
|
|
|
|
set SCRIPT_DIR=%~dp0
|
|
|
|
for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI
|
|
|
|
|
|
|
|
rem Detect JVM version to figure out appropriate executable to use
|
2013-09-19 10:32:33 -04:00
|
|
|
if not exist "%JAVA_HOME%\bin\java.exe" (
|
2014-04-19 23:46:24 -04:00
|
|
|
echo JAVA_HOME points to an invalid Java installation (no java.exe found in "%JAVA_HOME%"^). Exiting...
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-19 10:32:33 -04:00
|
|
|
)
|
2013-09-18 10:04:10 -04:00
|
|
|
"%JAVA_HOME%\bin\java" -version 2>&1 | find "64-Bit" >nul:
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-10-14 16:55:05 -04:00
|
|
|
if errorlevel 1 goto x86
|
|
|
|
set EXECUTABLE=%ES_HOME%\bin\elasticsearch-service-x64.exe
|
|
|
|
set SERVICE_ID=elasticsearch-service-x64
|
|
|
|
set ARCH=64-bit
|
|
|
|
goto checkExe
|
|
|
|
|
|
|
|
:x86
|
|
|
|
set EXECUTABLE=%ES_HOME%\bin\elasticsearch-service-x86.exe
|
|
|
|
set SERVICE_ID=elasticsearch-service-x86
|
|
|
|
set ARCH=32-bit
|
|
|
|
|
|
|
|
:checkExe
|
2013-09-16 05:57:55 -04:00
|
|
|
if EXIST "%EXECUTABLE%" goto okExe
|
|
|
|
echo elasticsearch-service-(x86|x64).exe was not found...
|
|
|
|
|
|
|
|
:okExe
|
|
|
|
set ES_VERSION=${project.version}
|
|
|
|
|
2013-10-14 16:55:05 -04:00
|
|
|
if "%LOG_DIR%" == "" set LOG_DIR=%ES_HOME%\logs
|
2013-09-16 05:57:55 -04:00
|
|
|
|
|
|
|
if "x%1x" == "xx" goto displayUsage
|
|
|
|
set SERVICE_CMD=%1
|
|
|
|
shift
|
|
|
|
if "x%1x" == "xx" goto checkServiceCmd
|
|
|
|
set SERVICE_ID=%1
|
|
|
|
|
|
|
|
:checkServiceCmd
|
|
|
|
|
2013-10-14 16:55:05 -04:00
|
|
|
if "%LOG_OPTS%" == "" set LOG_OPTS=--LogPath "%LOG_DIR%" --LogPrefix "%SERVICE_ID%" --StdError auto --StdOutput auto
|
2013-09-16 05:57:55 -04:00
|
|
|
|
|
|
|
if /i %SERVICE_CMD% == install goto doInstall
|
|
|
|
if /i %SERVICE_CMD% == remove goto doRemove
|
|
|
|
if /i %SERVICE_CMD% == start goto doStart
|
|
|
|
if /i %SERVICE_CMD% == stop goto doStop
|
|
|
|
if /i %SERVICE_CMD% == manager goto doManagment
|
|
|
|
echo Unknown option "%SERVICE_CMD%"
|
|
|
|
|
|
|
|
:displayUsage
|
|
|
|
echo.
|
|
|
|
echo Usage: service.bat install^|remove^|start^|stop^|manager [SERVICE_ID]
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
|
|
|
|
:doStart
|
|
|
|
"%EXECUTABLE%" //ES//%SERVICE_ID% %LOG_OPTS%
|
|
|
|
if not errorlevel 1 goto started
|
|
|
|
echo Failed starting '%SERVICE_ID%' service
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
:started
|
|
|
|
echo The service '%SERVICE_ID%' has been started
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
|
|
|
|
:doStop
|
|
|
|
"%EXECUTABLE%" //SS//%SERVICE_ID% %LOG_OPTS%
|
|
|
|
if not errorlevel 1 goto stopped
|
|
|
|
echo Failed stopping '%SERVICE_ID%' service
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
:stopped
|
|
|
|
echo The service '%SERVICE_ID%' has been stopped
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
|
|
|
|
:doManagment
|
|
|
|
set EXECUTABLE_MGR=%ES_HOME%\bin\elasticsearch-service-mgr.exe
|
|
|
|
"%EXECUTABLE_MGR%" //ES//%SERVICE_ID%
|
|
|
|
if not errorlevel 1 goto managed
|
|
|
|
echo Failed starting service manager for '%SERVICE_ID%'
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
:managed
|
2014-11-02 18:36:06 -05:00
|
|
|
echo Successfully started service manager for '%SERVICE_ID%'.
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
|
|
|
|
:doRemove
|
|
|
|
rem Remove the service
|
|
|
|
"%EXECUTABLE%" //DS//%SERVICE_ID% %LOG_OPTS%
|
|
|
|
if not errorlevel 1 goto removed
|
|
|
|
echo Failed removing '%SERVICE_ID%' service
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
:removed
|
|
|
|
echo The service '%SERVICE_ID%' has been removed
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
|
|
|
|
:doInstall
|
2013-09-19 10:32:33 -04:00
|
|
|
echo Installing service : "%SERVICE_ID%"
|
|
|
|
echo Using JAVA_HOME (%ARCH%): "%JAVA_HOME%"
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-09-19 10:32:33 -04:00
|
|
|
rem Check JVM server dll first
|
2013-09-16 05:57:55 -04:00
|
|
|
set JVM_DLL=%JAVA_HOME%\jre\bin\server\jvm.dll
|
2013-10-24 08:09:07 -04:00
|
|
|
if exist "%JVM_DLL%" goto foundJVM
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-10-24 08:09:07 -04:00
|
|
|
rem Check 'server' JRE (JRE installed on Windows Server)
|
|
|
|
set JVM_DLL=%JAVA_HOME%\bin\server\jvm.dll
|
2013-10-14 16:55:05 -04:00
|
|
|
if exist "%JVM_DLL%" goto foundJVM
|
2013-09-19 10:32:33 -04:00
|
|
|
|
2013-10-24 08:09:07 -04:00
|
|
|
rem Fallback to 'client' JRE
|
2013-09-19 10:32:33 -04:00
|
|
|
set JVM_DLL=%JAVA_HOME%\bin\client\jvm.dll
|
|
|
|
|
2013-10-14 16:55:05 -04:00
|
|
|
if exist "%JVM_DLL%" (
|
2013-09-19 10:32:33 -04:00
|
|
|
echo Warning: JAVA_HOME points to a JRE and not JDK installation; a client (not a server^) JVM will be used...
|
|
|
|
) else (
|
|
|
|
echo JAVA_HOME points to an invalid Java installation (no jvm.dll found in "%JAVA_HOME%"^). Existing...
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-19 10:32:33 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
:foundJVM
|
2013-10-14 16:55:05 -04:00
|
|
|
if "%ES_MIN_MEM%" == "" set ES_MIN_MEM=256m
|
|
|
|
if "%ES_MAX_MEM%" == "" set ES_MAX_MEM=1g
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-10-14 16:55:05 -04:00
|
|
|
if NOT "%ES_HEAP_SIZE%" == "" set ES_MIN_MEM=%ES_HEAP_SIZE%
|
|
|
|
if NOT "%ES_HEAP_SIZE%" == "" set ES_MAX_MEM=%ES_HEAP_SIZE%
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-09-26 16:25:04 -04:00
|
|
|
call:convertxm %ES_MIN_MEM% JVM_XMS
|
|
|
|
call:convertxm %ES_MAX_MEM% JVM_XMX
|
|
|
|
|
2014-10-27 11:22:43 -04:00
|
|
|
REM java_opts might be empty - init to avoid tripping commons daemon (if the command starts with ;)
|
2013-11-08 08:30:25 -05:00
|
|
|
if "%JAVA_OPTS%" == "" set JAVA_OPTS=-XX:+UseParNewGC
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2014-10-27 11:22:43 -04:00
|
|
|
CALL %ES_HOME%\bin\elasticsearch.in.bat
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-09-26 16:25:04 -04:00
|
|
|
rem thread stack size
|
|
|
|
set JVM_SS=256
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-10-14 16:55:05 -04:00
|
|
|
if "%DATA_DIR%" == "" set DATA_DIR=%ES_HOME%\data
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-10-14 16:55:05 -04:00
|
|
|
if "%WORK_DIR%" == "" set WORK_DIR=%ES_HOME%
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-10-14 16:55:05 -04:00
|
|
|
if "%CONF_DIR%" == "" set CONF_DIR=%ES_HOME%\config
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-10-14 16:55:05 -04:00
|
|
|
if "%CONF_FILE%" == "" set CONF_FILE=%ES_HOME%\config\elasticsearch.yml
|
2013-09-16 05:57:55 -04:00
|
|
|
|
|
|
|
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%"
|
|
|
|
|
2013-09-26 16:25:04 -04:00
|
|
|
set JVM_OPTS=%JAVA_OPTS: =;%
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-11-08 08:30:25 -05:00
|
|
|
if not "%ES_JAVA_OPTS%" == "" set JVM_ES_JAVA_OPTS=%ES_JAVA_OPTS: =#%
|
|
|
|
if not "%ES_JAVA_OPTS%" == "" set JVM_OPTS=%JVM_OPTS%;%JVM_ES_JAVA_OPTS%
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2013-10-24 06:39:57 -04:00
|
|
|
if "%ES_START_TYPE%" == "" set ES_START_TYPE=manual
|
|
|
|
if "%ES_STOP_TIMEOUT%" == "" set ES_STOP_TIMEOUT=0
|
|
|
|
|
2014-01-06 15:58:46 -05:00
|
|
|
"%EXECUTABLE%" //IS//%SERVICE_ID% --Startup %ES_START_TYPE% --StopTimeout %ES_STOP_TIMEOUT% --StartClass org.elasticsearch.bootstrap.Elasticsearch --StopClass org.elasticsearch.bootstrap.Elasticsearch --StartMethod main --StopMethod close --Classpath "%ES_CLASSPATH%" --JvmSs %JVM_SS% --JvmMs %JVM_XMS% --JvmMx %JVM_XMX% --JvmOptions %JVM_OPTS% ++JvmOptions %ES_PARAMS% %LOG_OPTS% --PidFile "%SERVICE_ID%.pid" --DisplayName "Elasticsearch %ES_VERSION% (%SERVICE_ID%)" --Description "Elasticsearch %ES_VERSION% Windows Service - http://elasticsearch.org" --Jvm "%JVM_DLL%" --StartMode jvm --StopMode jvm --StartPath "%ES_HOME%"
|
2013-09-16 05:57:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
if not errorlevel 1 goto installed
|
|
|
|
echo Failed installing '%SERVICE_ID%' service
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
|
|
|
|
:installed
|
|
|
|
echo The service '%SERVICE_ID%' has been installed.
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
|
|
|
|
:err
|
|
|
|
echo JAVA_HOME environment variable must be set!
|
|
|
|
pause
|
2013-09-26 16:25:04 -04:00
|
|
|
goto:eof
|
|
|
|
|
|
|
|
rem ---
|
|
|
|
rem Function for converting Xm[s|x] values into MB which Commons Daemon accepts
|
|
|
|
rem ---
|
|
|
|
:convertxm
|
|
|
|
set value=%~1
|
|
|
|
rem extract last char (unit)
|
|
|
|
set unit=%value:~-1%
|
|
|
|
rem assume the unit is specified
|
|
|
|
set conv=%value:~0,-1%
|
|
|
|
|
|
|
|
if "%unit%" == "k" goto kilo
|
|
|
|
if "%unit%" == "K" goto kilo
|
|
|
|
if "%unit%" == "m" goto mega
|
|
|
|
if "%unit%" == "M" goto mega
|
|
|
|
if "%unit%" == "g" goto giga
|
|
|
|
if "%unit%" == "G" goto giga
|
|
|
|
|
|
|
|
rem no unit found, must be bytes; consider the whole value
|
|
|
|
set conv=%value%
|
|
|
|
rem convert to KB
|
|
|
|
set /a conv=%conv% / 1024
|
|
|
|
:kilo
|
|
|
|
rem convert to MB
|
|
|
|
set /a conv=%conv% / 1024
|
|
|
|
goto mega
|
|
|
|
:giga
|
|
|
|
rem convert to MB
|
|
|
|
set /a conv=%conv% * 1024
|
|
|
|
:mega
|
|
|
|
set "%~2=%conv%"
|
|
|
|
goto:eof
|
2013-09-16 05:57:55 -04:00
|
|
|
|
2014-10-27 11:22:43 -04:00
|
|
|
ENDLOCAL
|