anchor.diff:  rem Detect JVM version to figure out appropriate executable to use
   if not exist "%JAVA_HOME%\bin\java.exe" (
   echo JAVA_HOME points to an invalid Java installation (no java.exe found in "%JAVA_HOME%"^). Existing...
  -goto finally
  +goto:eof
   )
   "%JAVA_HOME%\bin\java" -version 2>&1 | find "64-Bit" >nul:
   
  
positive.code: :displayUsage
  echo.
  echo Usage: service.bat install^|remove^|start^|stop^|manager [SERVICE_ID]
  goto finally
  
  :doStart
  "%EXECUTABLE%" //ES//%SERVICE_ID% %LOG_OPTS%
  if not errorlevel 1 goto started
  echo Failed starting '%SERVICE_ID%' service
  goto finally
  :started
  echo The service '%SERVICE_ID%' has been started
  goto finally
  
  :doStop
  "%EXECUTABLE%" //SS//%SERVICE_ID% %LOG_OPTS%
  if not errorlevel 1 goto stopped
  echo Failed stopping '%SERVICE_ID%' service
  goto finally
  :stopped
  echo The service '%SERVICE_ID%' has been stopped
  goto finally
  
  :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%'
  goto finally
  :managed
  echo Succesfully started service manager for '%SERVICE_ID%'.
  goto finally
  
  :doRemove
  rem Remove the service
  "%EXECUTABLE%" //DS//%SERVICE_ID% %LOG_OPTS%
  if not errorlevel 1 goto removed
  echo Failed removing '%SERVICE_ID%' service
  goto finally
  :removed
  echo The service '%SERVICE_ID%' has been removed
  goto finally
  
  :doInstall
  echo Installing service      :  "%SERVICE_ID%"
  
negative.code: 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: =;%
  
  if not "%ES_JAVA_OPTS%" == "" (
  set JVM_ES_JAVA_OPTS=%ES_JAVA_OPTS: =#%
  set JVM_OPTS=%JVM_OPTS%;%JVM_ES_JAVA_OPTS%
  )
  
  "%EXECUTABLE%" //IS//%SERVICE_ID% --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%"
  
  
  if not errorlevel 1 goto installed
  echo Failed installing '%SERVICE_ID%' service
  goto:eof
  
  :installed
  echo The service '%SERVICE_ID%' has been installed.
  goto:eof
  
  :err
  echo JAVA_HOME environment variable must be set!
  pause
  
  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
  
  ENDLOCAL