@echo off
rem ---------------------------------------------------------------------------
rem
rem VSM HA SERVICE
rem
rem ---------------------------------------------------------------------------
rem set env
set HA_DIR=%~dp0

set COLLECTOR_JRE_HOME=%HA_DIR%\jre7u25
set COLLECTOR_LOG_HOME=%HA_DIR%\log
set LIBPATH=%HA_DIR%\lib
setlocal
rem The service names (make sure they does not clash with an existing service)
set SERVICE_JVM=VSMHA

rem my location
set MYPATH=%~dp0

rem location of Prunsrv
set PATH_PRUNSRV=%MYPATH%
set PR_LOGPATH=%PATH_PRUNSRV%
rem location of jarfile
set PATH_JAR=%MYPATH%

rem Allow prunsrv to be overridden
if "%PRUNSRV%" == "" set PRUNSRV=%PATH_PRUNSRV%VSMHA
if "%1" == "" goto displayUsage
rem if "%2" == "" goto setServiceName
rem set SERVICE_NAME=%2
rem set PR_DISPLAYNAME=Apache Tomcat %2
:setServiceName
if %1 == install goto doInstall
if %1 == remove goto doRemove
if %1 == uninstall goto doRemove
echo Unknown parameter "%1"
:displayUsage
echo.
echo Usage: VSMHAService.bat install/remove
goto end

:doRemove
echo Removing %SERVICE_JVM%
"%PRUNSRV%" //DS//%SERVICE_JVM%
goto end

:doInstall
rem Install the 2 services
set PR_JVM=%COLLECTOR_JRE_HOME%\bin\server\jvm.dll
echo PR_JVM : %PR_JVM%

echo Installing %SERVICE_JVM%
"%PRUNSRV%" //DS//%SERVICE_JVM%
"%PRUNSRV%" //IS//%SERVICE_JVM% --StartClass=com.hs.ha.HaMain --StopClass=com.hs.ha.HaMain --StopMethod=stop --Description "VSM HA/OS Platform: Windows x86" --DisplayName "VSM HA Service" --Startup=auto
echo Setting the parameters for %SERVICE_JVM%
"%PRUNSRV%" //US//%SERVICE_JVM% --StopMode=jvm --StartMode=jvm --Jvm=%PR_JVM%  --ServiceUser=LocalSystem
"%PRUNSRV%" //US//%SERVICE_JVM% --StdOutput %COLLECTOR_LOG_HOME%\haservice-stdout.log --StdError %COLLECTOR_LOG_HOME%\haservice-stderr.log 
"%PRUNSRV%" //US//%SERVICE_JVM% --Classpath "%LIBPATH%\log4j-1.2.17.jar;%LIBPATH%\dom4j-2.1.1.jar;%LIBPATH%\jaxen-1.1.6.jar;%LIBPATH%\mysql-connector-java-8.0.16.jar;%LIBPATH%\ha.jar"
"%PRUNSRV%" //US//%SERVICE_JVM% --JvmOptions "-Xms128m;-XX:+HeapDumpOnOutOfMemoryError"
echo Installation of %SERVICE_JVM% is complete
echo Finished
:end
exit

