[20391] | 1 | @echo off
|
---|
| 2 | SETLOCAL
|
---|
| 3 |
|
---|
[20896] | 4 | if "%serverlang%" == "" set serverlang=en
|
---|
[20635] | 5 | set java_min_version=1.5.0_00
|
---|
[20896] | 6 | set PROGNAME=gs2-server
|
---|
| 7 | if "%PROGABBR%" == "" set PROGABBR=GSI
|
---|
[20391] | 8 | pushd "%CD%"
|
---|
| 9 | CD /D "%~dp0"
|
---|
| 10 |
|
---|
| 11 | echo Greenstone 2 Server
|
---|
| 12 | echo Copyright (C) 2009, New Zealand Digital Library Project, University Of Waikato
|
---|
| 13 | echo This software comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.txt
|
---|
| 14 | echo This is free software, and you are welcome to redistribute it
|
---|
| 15 |
|
---|
| 16 | :: -------- Run the Greenstone 2 Server --------
|
---|
| 17 |
|
---|
| 18 | :: ---- Determine GSDLHOME ----
|
---|
| 19 | set gsdl2path=
|
---|
| 20 |
|
---|
| 21 | :: Some users may set the above line manually
|
---|
| 22 | if "%gsdl2path%" == "" (
|
---|
| 23 | set GSDLHOME=%CD%
|
---|
| 24 | set gsdl2path=%CD%
|
---|
| 25 | )
|
---|
| 26 | echo GS2 Home: %GSDLHOME%
|
---|
| 27 |
|
---|
| 28 | :: Setup Greenstone2, unless it has already been done
|
---|
[20436] | 29 | :: If either GSDLHOME or GSDLOS is not set, need to run setup.bat first
|
---|
| 30 | :: OR operations in an IF stmt: http://fixunix.com/ms-dos/21057-how-implement-if-condition-batch-file.html
|
---|
| 31 | for %%i in ("%GSDLOS%" "%GSDLHOME%") do if %%i == "" set OR=True
|
---|
| 32 | if "%OR%" == "True" (
|
---|
| 33 | pushd "%gsdl2path%"
|
---|
[20391] | 34 | call setup.bat
|
---|
[20655] | 35 | rem echo **** GSDLOS: %GSDLOS% and GSDLHOME: %GSDLHOME%
|
---|
[20391] | 36 | popd
|
---|
| 37 | )
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | :: First test that there is actually something that can be run...
|
---|
| 41 | :: Exit if the apache-httpd folder doesn't exist for some reason
|
---|
| 42 | :: (The errors reported when the apache webserver does not exist
|
---|
| 43 | :: in the correct location are not at all helpful).
|
---|
| 44 |
|
---|
| 45 | :: "You cannot use the if command to test directly for a directory, but
|
---|
| 46 | :: the null (NUL) device does exist in every directory. As a result, you
|
---|
| 47 | :: can test for the null device to determine whether a directory exists."
|
---|
[20915] | 48 | rem echo "%GSDLHOME%\apache-httpd\nul"
|
---|
[20905] | 49 | if not exist "%GSDLHOME%\apache-httpd\*" (
|
---|
[20391] | 50 | echo.
|
---|
| 51 | echo UNABLE TO CONTINUE: There is no apache-httpd directory.
|
---|
| 52 | echo It does not look like the local apache webserver has been installed.
|
---|
| 53 | echo Exiting...
|
---|
| 54 | echo.
|
---|
| 55 | goto exit
|
---|
| 56 | )
|
---|
| 57 | :: exit 1
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | :: If there's no llssite.cfg file, copy from the template
|
---|
| 61 | if exist "%GSDLHOME%\llssite.cfg" goto cfgfile
|
---|
| 62 | if exist "%GSDLHOME%\llssite.cfg.in" (
|
---|
| 63 | copy "%GSDLHOME%\llssite.cfg.in" "%GSDLHOME%\llssite.cfg"
|
---|
| 64 | ) else (
|
---|
| 65 | echo Warning: could not find llssite.cfg.in to create llssite.cfg from.
|
---|
| 66 | )
|
---|
| 67 |
|
---|
| 68 | :cfgfile
|
---|
| 69 | :: ---- Determine GSDLHOME ----
|
---|
| 70 | :: JRE_HOME or JAVA_HOME must be set correctly to run this program
|
---|
| 71 | bin\windows\search4j -m %java_min_version% > nul
|
---|
| 72 | echo.
|
---|
| 73 | :: In Java code, '...getResourceAsStream("build.properties")'
|
---|
| 74 | :: needs up to be in the right directory when run
|
---|
| 75 | if %ERRORLEVEL% equ 0 pushd %GSDL2PATH%
|
---|
| 76 |
|
---|
| 77 | :: http://ss64.com/nt/call.html (and leave in trailing slash)
|
---|
[20905] | 78 | call :isinpath "%GSDLHOME%\lib\java"
|
---|
[20391] | 79 |
|
---|
| 80 | :: After the call, we come back here
|
---|
| 81 | goto chkjava
|
---|
| 82 |
|
---|
| 83 | :isinpath
|
---|
[20392] | 84 | :: http://ss64.com/nt/syntax-replace.html and http://ss64.com/nt/syntax-args.html
|
---|
| 85 | :: (Does not work: section "Finding items within the PATH environment variable")
|
---|
[20391] | 86 | :: Instead, we expand the filepath of parameter 1 to its full path and
|
---|
| 87 | :: try to subtract it from the classpath.
|
---|
[20392] | 88 | ::call set test_cpath=%%CLASSPATH:%~f1=%%
|
---|
[22388] | 89 | call set test_cpath=%%CLASSPATH:%~1=%%
|
---|
[20391] | 90 |
|
---|
[22388] | 91 | :: If the classpath was not empty to begin with and if there IS a difference in
|
---|
| 92 | :: the classpath before and after, then the filepath was already on the classpath
|
---|
| 93 | if not "%CLASSPATH%" == "" if not "%CLASSPATH%" == "%test_cpath%" (
|
---|
| 94 | echo - CLASSPATH already correct:
|
---|
[20391] | 95 | echo %CLASSPATH%
|
---|
| 96 | goto :eof
|
---|
| 97 | )
|
---|
| 98 |
|
---|
| 99 | :: If there was NO difference in the classpath before and after,
|
---|
| 100 | :: then the filepath needs to be added to the classpath
|
---|
| 101 | set CLASSPATH=%GSDLHOME%\lib\java;%CLASSPATH%
|
---|
| 102 |
|
---|
[20392] | 103 | :: http://ss64.com/nt/for_r.html and (for call) http://ss64.com/nt/for.html
|
---|
[20391] | 104 | :: http://ss64.com/nt/syntax-args.html
|
---|
[20905] | 105 | FOR /R "%GSDLHOME%\lib\java" %%G IN (*.jar) DO call :putinpath "%%G"
|
---|
[20391] | 106 | echo - Adjusted CLASSPATH
|
---|
| 107 | echo.
|
---|
| 108 | ::echo CLASSPATH:& echo %CLASSPATH%
|
---|
| 109 | goto :eof
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | :putinpath
|
---|
[20905] | 113 | set jarfile=%1
|
---|
| 114 | ::strip quotes around jarfile path, since we can't update classpath with quotes
|
---|
| 115 | set jarfile=%jarfile:"=%
|
---|
| 116 | echo jarfile: %jarfile%
|
---|
| 117 | set CLASSPATH=%CLASSPATH%;%jarfile%
|
---|
[20391] | 118 | goto :eof
|
---|
| 119 |
|
---|
| 120 | :: ---- Check Java ----
|
---|
| 121 | :chkjava
|
---|
[20655] | 122 | :: call the script with source, so that we have the variables JAVA_EXECUTABLE and GS_JAVA_HOME it sets
|
---|
[20391] | 123 | set exit_status=0
|
---|
| 124 | :: Need to find Java. If found, JAVA_EXECUTABLE will be set
|
---|
| 125 | :: call findjava.bat %serverlang% %PROGNAME%
|
---|
[20934] | 126 | if "%GSDL3SRCHOME%" == "" (set _VERSION=2) else (set _VERSION=3)
|
---|
[20478] | 127 | call "%GSDLHOME%\findjava.bat"
|
---|
[20391] | 128 | if "%JAVA_EXECUTABLE%" == "" echo **** No Java executable found& goto exit
|
---|
[20655] | 129 | set PATH=%GS_JAVA_HOME%\bin;%PATH%
|
---|
[20391] | 130 |
|
---|
| 131 |
|
---|
| 132 | :: ---- Run the Greenstone Server Interface ----
|
---|
[20896] | 133 | :: Some informative messages to direct the users to the logs
|
---|
| 134 | if "%serverlang%" == "en" (
|
---|
| 135 | echo ***************************************************************
|
---|
[20905] | 136 | echo Starting the Greenstone Server Interface ^(GSI^)...
|
---|
[20896] | 137 | echo.
|
---|
| 138 | echo Server log messages go to:
|
---|
[20905] | 139 | echo "%GSDLHOME%\etc\logs-gsi\server.log"
|
---|
[20896] | 140 | echo.
|
---|
| 141 | echo Using Apache web server located at:
|
---|
[20905] | 142 | echo "%GSDLHOME%\apache-httpd\%GSDLOS%\bin\httpd"
|
---|
[20896] | 143 | echo The Apache error log is at:
|
---|
[20905] | 144 | echo "%GSDLHOME%\apache-httpd\%GSDLOS%\logs\error_log"
|
---|
[20896] | 145 | echo The Apache configuration file template is at:
|
---|
[20905] | 146 | echo "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf.in"
|
---|
[20896] | 147 | echo This is used to generate:
|
---|
[20905] | 148 | echo "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf"
|
---|
[20896] | 149 | echo each time Enter Library is pressed or otherwise activated.
|
---|
| 150 | echo ***************************************************************
|
---|
| 151 | echo.
|
---|
| 152 | )
|
---|
[20391] | 153 | echo.
|
---|
[21966] | 154 |
|
---|
| 155 | :: GLI launches gs2-server.bat with:
|
---|
| 156 | :: cmd /c start "window" "c:\path to\gs2-server.bat" --config=c:\path to\glisite.cfg [--quit=portnum]
|
---|
| 157 | :: The configfile param could contain spaces, in which case its space-separated parts spread over
|
---|
| 158 | :: multiple parameters . Need to handle things the following way, since using quotes to embed the
|
---|
| 159 | :: parameters breaks the start command, see http://ss64.com/nt/start.html
|
---|
| 160 | :: This script is launched by the start cmd as:
|
---|
| 161 | :: "c:\path to\gs2-server.bat" --config=c:\path to\config.cfg [--quit=portnum].
|
---|
| 162 | :: But if the parameter following --config=<some string> doesn't start with a double hyphen, we
|
---|
| 163 | :: assume it to be part of the config parameter, as the configfile path may have contained spaces.
|
---|
| 164 |
|
---|
| 165 | :: Store all parameters together in config file var: we may or may not have a portnumber
|
---|
[22084] | 166 | :: Get everything after the "--quitport=", if anything, and store it in port var. If no port, nothing to do.
|
---|
[21966] | 167 | set conf=%*
|
---|
[22084] | 168 | if "%conf%" == "" goto :runit
|
---|
| 169 |
|
---|
[21966] | 170 | set port=%conf:*--quitport=%
|
---|
| 171 | if "%conf%" == "%port%" (
|
---|
| 172 | set port=
|
---|
| 173 | goto :runit
|
---|
| 174 | ) else (
|
---|
| 175 | set port=%port:~1%
|
---|
| 176 | )
|
---|
| 177 |
|
---|
| 178 | :: Because we got here, need to adjust conf by removing " --quitport=" from it and prefixing this to port
|
---|
| 179 | call set conf=%%conf:%port%=%%
|
---|
| 180 | set conf=%conf:~0,-12%
|
---|
| 181 | set port=--quitport=%port%
|
---|
| 182 |
|
---|
| 183 | :: Remove trailing spaces from conf and port
|
---|
| 184 | :: (We'll put the all-important quotes around conf and port when the actual java cmd is launched)
|
---|
| 185 | set tmp=%conf%
|
---|
| 186 | call :trim %tmp%
|
---|
| 187 | set conf=%tmp%
|
---|
| 188 | set tmp=%port%
|
---|
| 189 | call :trim %port%
|
---|
| 190 | set port=%tmp%
|
---|
| 191 | set tmp=
|
---|
| 192 |
|
---|
| 193 | goto :runit
|
---|
| 194 |
|
---|
| 195 | :: http://www.computing.net/answers/programming/dos-batch-remove-trailing-space/9270.html
|
---|
| 196 | :trim
|
---|
| 197 | set tmp=%*
|
---|
| 198 | goto :eof
|
---|
| 199 |
|
---|
| 200 | :runit
|
---|
| 201 | ::echo port: %port%& echo conf: %conf%& echo.& echo.
|
---|
| 202 | :: "%JAVA_EXECUTABLE%" org.greenstone.server.Server2 "%GSDLHOME%" "%serverlang%" %*
|
---|
| 203 | "%JAVA_EXECUTABLE%" org.greenstone.server.Server2 "%GSDLHOME%" "%serverlang%" "%conf%" "%port%"
|
---|
| 204 |
|
---|
| 205 |
|
---|
| 206 | :: The 1st argument to gs2-server.bat (if any) would be --config, the 2nd is the config filename.
|
---|
| 207 | :: Both are stored in %conf% now. If the config file is glisite.cfg, then this script was launched through
|
---|
| 208 | :: GLI and would have opened a DOS console. Need to exit from this script then to close the console.
|
---|
[22084] | 209 | :: Remove --config=prefix and do a case insensitive comparison, since filepaths can have uppercase chars
|
---|
| 210 | if "%conf%" == "" goto exit
|
---|
[21966] | 211 | if /i "%conf:~9%" == "%GSDLHOME%\glisite.cfg" goto quitcmd
|
---|
[20391] | 212 | goto exit
|
---|
| 213 |
|
---|
[20478] | 214 | :: Exit the batch script (close the console)
|
---|
| 215 | :quitcmd
|
---|
| 216 | popd
|
---|
| 217 | ENDLOCAL
|
---|
| 218 | exit 0
|
---|
| 219 |
|
---|
| 220 | :: Just end the script without closing the console
|
---|
[20391] | 221 | :exit
|
---|
| 222 | popd
|
---|
| 223 | ENDLOCAL
|
---|