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