/ launcher / service.bat
service.bat
  1  @echo off
  2  echo This program will attempt to set up a procrun windows service
  3  echo for ArchivesSpace.
  4  echo.
  5  echo Prerequisites:
  6  echo 1) Download procrun
  7  echo  ( http://commons.apache.org/proper/commons-daemon/procrun.html )
  8  echo and put the execuitables ( prunsrv.exe and prunmgr.exe )
  9  echo into your archivesspace directory.
 10  echo.
 11  echo.
 12  echo 2) You must have JAVA_HOME defined as a global variable, pointing
 13  echo to your systems java home ( e.g. C:\Program Files\Java\jre7 ).
 14  echo To find this, you can use "where java" command. The home will be the
 15  echo directory above "bin\java.exe".
 16  echo.
 17  echo.
 18  pause
 19  
 20  SETLOCAL ENABLEDELAYEDEXPANSION
 21  
 22  cd /d %~dp0%..
 23  set ASPACE_LAUNCHER_BASE=%CD%
 24  
 25  REM
 26  REM Check for Java.
 27  REM
 28  
 29  java -version
 30  if %ERRORLEVEL% NEQ 0 goto nojava
 31  goto checkJavaHome
 32  
 33  :nojava
 34  echo *** Could not run your 'java' executable.
 35  echo *** Please ensure that Java 1.7 or 1.8 is installed on your machine.
 36  goto end
 37  
 38  :checkJavaHome
 39  if exist "%JAVA_HOME%" goto checkProcrun
 40  echo You must define JAVA_HOME to point to your installed Java
 41  echo as a global variable. Please define this and try again
 42  goto end
 43  
 44  :checkProcrun
 45  if exist "%ASPACE_LAUNCHER_BASE%\prunsrv.exe" goto setEnv
 46  echo Please download Procrun http://commons.apache.org/proper/commons-daemon/procrun.html
 47  echo and install the prunsrv.exe into your ArchivesSpace directory.
 48  goto end
 49  
 50  :setEnv
 51  
 52  copy "%ASPACE_LAUNCHER_BASE%\prunsrv.exe" "%ASPACE_LAUNCHER_BASE%\ArchivesSpaceService.exe"
 53  copy "%ASPACE_LAUNCHER_BASE%\prunmgr.exe" "%ASPACE_LAUNCHER_BASE%\ArchivesSpaceServicew.exe"
 54  
 55  set INSTALL_PROCESS="%ASPACE_LAUNCHER_BASE%\ArchivesSpaceService.exe"
 56  
 57  set LOG_DIR="%ASPACE_LAUNCHER_BASE%\logs"
 58  set LOG_PREFIX=as_service.out
 59  
 60  set AS_LOG="%LOG_DIR%\archivesspace.out"
 61  set AS_ERROR_LOG="%LOG_DIR%\archivesspace_error.out"
 62  
 63  set LAUNCHER_SCRIPT="%ASPACE_LAUNCHER_BASE%\launcher\launcher.rb"
 64  
 65  set LAUNCHER_LIB="%ASPACE_LAUNCHER_BASE%\launcher\lib"
 66  set LAUNCHER_JARS=
 67  FOR /f %%c in ('dir /b /s %LAUNCHER_LIB%\*.jar') do (
 68  	set LAUNCHER_JARS=!LAUNCHER_JARS!;%%c
 69  )
 70  
 71  set AS_LIB="%ASPACE_LAUNCHER_BASE%\lib"
 72  set AS_JARS=
 73  FOR /f %%c in ('dir /b /s %AS_LIB%\*.jar') do (
 74  	set AS_JARS=!AS_JARS!;%%c
 75  )
 76  
 77  set GEM_HOME="%ASPACE_LAUNCHER_BASE%\gems"
 78  
 79  set JRUBY=
 80  FOR /D %%c IN ("!GEM_HOME!\gems\jruby-*") DO (
 81    for /f %%a IN ('dir /b /s %%c\lib\*.jar') DO (
 82  	  set JRUBY=!JRUBY!;%%a
 83    )
 84  )
 85  goto :doInstall
 86  
 87  :doInstall
 88  %INSTALL_PROCESS% //IS//ArchivesSpaceService --LogPath=%LOG_DIR% --LogPrefix=%LOG_PREFIX% --StdOutput=%AS_LOG% --StdError=%AS_ERROR_LOG%  --DisplayName="ArchivesSpaceService" --Startup=auto ++JvmOptions=-Darchivesspace-daemon=yes ++JvmOptions=%JAVA_OPTS% --JvmOptions=-Xss2m --JvmOptions=-Xmx1024m ++JvmOptions=-Dfile.encoding=UTF-8  --Install=%INSTALL_PROCESS% --StartMode=java --StopMode=java --Classpath="!AS_JARS!;!LAUNCHER_JARS!;!JRUBY!" ++StartParams="'%LAUNCHER_SCRIPT%'" --StartClass=org.jruby.Main ++StopParams="'%LAUNCHER_SCRIPT%'; stop" --StopTimeout=5  --StopClass=org.jruby.Main ++Environment='ASPACE_LAUNCHER_BASE=%ASPACE_LAUNCHER_BASE%'
 89  if not errorlevel 1 goto installed
 90  echo "There was a problem installing the service...please check the settings."
 91  goto end
 92  :installed
 93  
 94  
 95  echo.
 96  echo.
 97  echo.
 98  echo The service has been installed. There is now an
 99  echo ArchivesSpaceService execucitable and ArchivesSpaceServicew monitor.
100  
101  echo ArchivesSpaceService Options:
102  echo ArchivesSpaceService //TS// Run the service as a console app
103  echo ArchivesSpaceService //RS// Run the service
104  echo ArchivesSpaceService //SS// Stop the service
105  echo ArchivesSpaceService //US// Update service pamaters
106  echo ArchivesSpaceSerivce //DS// Delete service
107  
108  echo.
109  echo.
110  echo ArchivesSpaceServicew Options:
111  echo ArchivesSpaceServicew //ES// Start GUI service editor
112  echo ArchivesSpaceServicew //MS// Monitor service (puts an icon in system tray)
113  echo.
114  echo Enjoy.
115  
116  :end
117  echo Done