"Fossies" - the Fresh Open Source Software Archive

Member "elasticsearch-6.8.23/bin/elasticsearch-service.bat" (6 Jan 2022, 7549 Bytes) of package /linux/www/elasticsearch-6.8.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) MS DOS Batch source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "elasticsearch-service.bat": 6.8.22_vs_8.0.0-rc1.

A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.


    1 @echo off
    2 
    3 setlocal enabledelayedexpansion
    4 setlocal enableextensions
    5 
    6 call "%~dp0elasticsearch-env.bat" || exit /b 1
    7 
    8 set EXECUTABLE=%ES_HOME%\bin\elasticsearch-service-x64.exe
    9 if "%SERVICE_ID%" == "" set SERVICE_ID=elasticsearch-service-x64
   10 set ARCH=64-bit
   11 
   12 if EXIST "%EXECUTABLE%" goto okExe
   13 echo elasticsearch-service-x64.exe was not found...
   14 exit /B 1
   15 
   16 :okExe
   17 set ES_VERSION=6.8.23
   18 
   19 if "%SERVICE_LOG_DIR%" == "" set SERVICE_LOG_DIR=%ES_HOME%\logs
   20 
   21 if "x%1x" == "xx" goto displayUsage
   22 set SERVICE_CMD=%1
   23 shift
   24 if "x%1x" == "xx" goto checkServiceCmd
   25 set SERVICE_ID=%1
   26 
   27 :checkServiceCmd
   28 
   29 if "%LOG_OPTS%" == "" set LOG_OPTS=--LogPath "%SERVICE_LOG_DIR%" --LogPrefix "%SERVICE_ID%" --StdError auto --StdOutput auto
   30 
   31 if /i %SERVICE_CMD% == install goto doInstall
   32 if /i %SERVICE_CMD% == remove goto doRemove
   33 if /i %SERVICE_CMD% == start goto doStart
   34 if /i %SERVICE_CMD% == stop goto doStop
   35 if /i %SERVICE_CMD% == manager goto doManagment
   36 echo Unknown option "%SERVICE_CMD%"
   37 
   38 :displayUsage
   39 echo.
   40 echo Usage: elasticsearch-service.bat install^|remove^|start^|stop^|manager [SERVICE_ID]
   41 goto:eof
   42 
   43 :doStart
   44 "%EXECUTABLE%" //ES//%SERVICE_ID% %LOG_OPTS%
   45 if not errorlevel 1 goto started
   46 echo Failed starting '%SERVICE_ID%' service
   47 goto:eof
   48 :started
   49 echo The service '%SERVICE_ID%' has been started
   50 goto:eof
   51 
   52 :doStop
   53 "%EXECUTABLE%" //SS//%SERVICE_ID% %LOG_OPTS%
   54 if not errorlevel 1 goto stopped
   55 echo Failed stopping '%SERVICE_ID%' service
   56 goto:eof
   57 :stopped
   58 echo The service '%SERVICE_ID%' has been stopped
   59 goto:eof
   60 
   61 :doManagment
   62 set EXECUTABLE_MGR=%ES_HOME%\bin\elasticsearch-service-mgr.exe
   63 "%EXECUTABLE_MGR%" //ES//%SERVICE_ID%
   64 if not errorlevel 1 goto managed
   65 echo Failed starting service manager for '%SERVICE_ID%'
   66 goto:eof
   67 :managed
   68 echo Successfully started service manager for '%SERVICE_ID%'.
   69 goto:eof
   70 
   71 :doRemove
   72 rem Remove the service
   73 "%EXECUTABLE%" //DS//%SERVICE_ID% %LOG_OPTS%
   74 if not errorlevel 1 goto removed
   75 echo Failed removing '%SERVICE_ID%' service
   76 goto:eof
   77 :removed
   78 echo The service '%SERVICE_ID%' has been removed
   79 goto:eof
   80 
   81 :doInstall
   82 echo Installing service      :  "%SERVICE_ID%"
   83 echo Using JAVA_HOME (%ARCH%):  "%JAVA_HOME%"
   84 
   85 rem Check JVM server dll first
   86 if exist "%JAVA_HOME%\jre\bin\server\jvm.dll" (
   87     set JVM_DLL=\jre\bin\server\jvm.dll
   88     goto foundJVM
   89 )
   90 
   91 rem Check 'server' JRE (JRE installed on Windows Server)
   92 if exist "%JAVA_HOME%\bin\server\jvm.dll" (
   93     set JVM_DLL=\bin\server\jvm.dll
   94     goto foundJVM
   95 ) else (
   96     echo JAVA_HOME points to an invalid Java installation (no jvm.dll found in "%JAVA_HOME%"^). Exiting...
   97     goto:eof
   98 )
   99 
  100 :foundJVM
  101 set ES_JVM_OPTIONS=%ES_PATH_CONF%\jvm.options
  102 
  103 if not "%ES_JAVA_OPTS%" == "" set ES_JAVA_OPTS=%ES_JAVA_OPTS: =;%
  104 
  105 @setlocal
  106 for /F "usebackq delims=" %%a in (`"%JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.JvmOptionsParser" "!ES_JVM_OPTIONS!" || echo jvm_options_parser_failed"`) do set JVM_OPTIONS=%%a
  107 @endlocal & set "MAYBE_JVM_OPTIONS_PARSER_FAILED=%JVM_OPTIONS%" & set ES_JAVA_OPTS=%JVM_OPTIONS:${ES_TMPDIR}=!ES_TMPDIR!% %ES_JAVA_OPTS%
  108 
  109 if "%MAYBE_JVM_OPTIONS_PARSER_FAILED%" == "jvm_options_parser_failed" (
  110   exit /b 1
  111 )
  112 
  113 if not "%ES_JAVA_OPTS%" == "" set ES_JAVA_OPTS=%ES_JAVA_OPTS: =;%
  114 
  115 if "%ES_JAVA_OPTS:~-1%"==";" set ES_JAVA_OPTS=%ES_JAVA_OPTS:~0,-1%
  116 
  117 echo %ES_JAVA_OPTS%
  118 
  119 @setlocal EnableDelayedExpansion
  120 for %%a in ("%ES_JAVA_OPTS:;=","%") do (
  121   set var=%%a
  122   if "!var:~1,4!" == "-Xms" (
  123     set XMS=!var:~5,-1!
  124     call:convertxm !XMS! JVM_MS
  125   )
  126   if "!var:~1,16!" == "-XX:MinHeapSize=" (
  127     set XMS=!var:~17,-1!
  128     call:convertxm !XMS! JVM_MS
  129   )
  130   if "!var:~1,4!" == "-Xmx" (
  131     set XMX=!var:~5,-1!
  132     call:convertxm !XMX! JVM_MX
  133   )
  134   if "!var:~1,16!" == "-XX:MaxHeapSize=" (
  135     set XMX=!var:~17,-1!
  136     call:convertxm !XMX! JVM_MX
  137   )
  138   if "!var:~1,4!" == "-Xss" (
  139     set XSS=!var:~5,-1!
  140     call:convertxk !XSS! JVM_SS
  141   )
  142   if "!var:~1,20!" == "-XX:ThreadStackSize=" (
  143     set XSS=!var:~21,-1!
  144     call:convertxk !XSS! JVM_SS
  145   )
  146 )
  147 @endlocal & set JVM_MS=%JVM_MS% & set JVM_MX=%JVM_MX% & set JVM_SS=%JVM_SS%
  148 
  149 if "%JVM_MS%" == "" (
  150   echo minimum heap size not set; configure using -Xms via "%ES_JVM_OPTIONS%" or ES_JAVA_OPTS
  151   goto:eof
  152 )
  153 if "%JVM_MX%" == "" (
  154   echo maximum heap size not set; configure using -Xmx via "%ES_JVM_OPTIONS%" or ES_JAVA_OPTS
  155   goto:eof
  156 )
  157 if "%JVM_SS%" == "" (
  158   echo thread stack size not set; configure using -Xss via "%ES_JVM_OPTIONS%" or ES_JAVA_OPTS
  159   goto:eof
  160 )
  161 
  162 set ES_PARAMS=-Delasticsearch;-Des.path.home="%ES_HOME%";-Des.path.conf="%ES_PATH_CONF%";-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%";-Des.distribution.type="%ES_DISTRIBUTION_TYPE%"
  163 
  164 if "%ES_START_TYPE%" == "" set ES_START_TYPE=manual
  165 if "%ES_STOP_TIMEOUT%" == "" set ES_STOP_TIMEOUT=0
  166 
  167 if "%SERVICE_DISPLAY_NAME%" == "" set SERVICE_DISPLAY_NAME=Elasticsearch %ES_VERSION% (%SERVICE_ID%)
  168 if "%SERVICE_DESCRIPTION%" == "" set SERVICE_DESCRIPTION=Elasticsearch %ES_VERSION% Windows Service - https://elastic.co
  169 
  170 if not "%SERVICE_USERNAME%" == "" (
  171     if not "%SERVICE_PASSWORD%" == "" (
  172         set SERVICE_PARAMS=%SERVICE_PARAMS% --ServiceUser "%SERVICE_USERNAME%" --ServicePassword "%SERVICE_PASSWORD%"
  173     )
  174 )
  175 
  176 "%EXECUTABLE%" //IS//%SERVICE_ID% --Startup %ES_START_TYPE% --StopTimeout %ES_STOP_TIMEOUT% --StartClass org.elasticsearch.bootstrap.Elasticsearch --StartMethod main ++StartParams --quiet --StopClass org.elasticsearch.bootstrap.Elasticsearch --StopMethod close --Classpath "%ES_CLASSPATH%" --JvmMs %JVM_MS% --JvmMx %JVM_MX% --JvmSs %JVM_SS% --JvmOptions %ES_JAVA_OPTS% ++JvmOptions %ES_PARAMS% %LOG_OPTS% --PidFile "%SERVICE_ID%.pid" --DisplayName "%SERVICE_DISPLAY_NAME%" --Description "%SERVICE_DESCRIPTION%" --Jvm "%%JAVA_HOME%%%JVM_DLL%" --StartMode jvm --StopMode jvm --StartPath "%ES_HOME%" %SERVICE_PARAMS% ++Environment HOSTNAME="%%COMPUTERNAME%%"
  177 
  178 if not errorlevel 1 goto installed
  179 echo Failed installing '%SERVICE_ID%' service
  180 goto:eof
  181 
  182 :installed
  183 echo The service '%SERVICE_ID%' has been installed.
  184 goto:eof
  185 
  186 :err
  187 echo JAVA_HOME environment variable must be set!
  188 pause
  189 goto:eof
  190 
  191 rem ---
  192 rem Function for converting Xm[s|x] values into MB which Commons Daemon accepts
  193 rem ---
  194 :convertxm
  195 set value=%~1
  196 rem extract last char (unit)
  197 set unit=%value:~-1%
  198 rem assume the unit is specified
  199 set conv=%value:~0,-1%
  200 
  201 if "%unit%" == "k" goto kilo
  202 if "%unit%" == "K" goto kilo
  203 if "%unit%" == "m" goto mega
  204 if "%unit%" == "M" goto mega
  205 if "%unit%" == "g" goto giga
  206 if "%unit%" == "G" goto giga
  207 
  208 rem no unit found, must be bytes; consider the whole value
  209 set conv=%value%
  210 rem convert to KB
  211 set /a conv=%conv% / 1024
  212 :kilo
  213 rem convert to MB
  214 set /a conv=%conv% / 1024
  215 goto mega
  216 :giga
  217 rem convert to MB
  218 set /a conv=%conv% * 1024
  219 :mega
  220 set "%~2=%conv%"
  221 goto:eof
  222 
  223 :convertxk
  224 set value=%~1
  225 rem extract last char (unit)
  226 set unit=%value:~-1%
  227 rem assume the unit is specified
  228 set conv=%value:~0,-1%
  229 
  230 if "%unit%" == "k" goto kilo
  231 if "%unit%" == "K" goto kilo
  232 if "%unit%" == "m" goto mega
  233 if "%unit%" == "M" goto mega
  234 if "%unit%" == "g" goto giga
  235 if "%unit%" == "G" goto giga
  236 
  237 rem no unit found, must be bytes; consider the whole value
  238 set conv=%value%
  239 rem convert to KB
  240 set /a conv=%conv% / 1024
  241 goto kilo
  242 :mega
  243 rem convert to KB
  244 set /a conv=%conv% * 1024
  245 goto kilo
  246 :giga
  247 rem convert to KB
  248 set /a conv=%conv% * 1024 * 1024
  249 :kilo
  250 set "%~2=%conv%"
  251 goto:eof
  252 
  253 endlocal
  254 endlocal
  255 
  256 exit /b %ERRORLEVEL%