[20391] | 1 | @echo off
|
---|
[24829] | 2 | SETLOCAL enabledelayedexpansion
|
---|
[20391] | 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%" == "" (
|
---|
[24829] | 23 | set GSDLHOME=!CD!
|
---|
| 24 | set gsdl2path=!CD!
|
---|
[20391] | 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
|
---|
[24829] | 31 | (echo This is a temporary file. It is safe to delete it. > "!GSDLHOME!\etc\logs-gsi\testing.tmp" ) 2>nul
|
---|
[22572] | 32 | if exist "%GSDLHOME%\etc\logs-gsi\testing.tmp" goto deleteTempFile
|
---|
| 33 | if "%1" == "Elevated" goto printWarning
|
---|
| 34 | echo ... FAILED
|
---|
[24829] | 35 | echo The Greenstone server cannot write to the log directory (!GSDLHOME!\etc\logs-gsi)
|
---|
[22572] | 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
|
---|
[24829] | 42 | echo The Greenstone log directory does not exist (!GSDLHOME!\etc\logs-gsi). Please reinstall Greenstone.
|
---|
[22576] | 43 | pause
|
---|
| 44 | goto exit
|
---|
| 45 |
|
---|
[22572] | 46 | :printWarning
|
---|
| 47 | echo ... FAILED
|
---|
[24829] | 48 | echo The Greenstone server cannot write to the log directory (!GSDLHOME!\etc\logs-gsi).
|
---|
[22572] | 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
|
---|
[24829] | 66 | for %%i in ("!GSDLOS!" "!GSDLHOME!") do if %%i == "" set OR=True
|
---|
[20436] | 67 | if "%OR%" == "True" (
|
---|
[24829] | 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" (
|
---|
[24829] | 99 | copy "!GSDLHOME!\llssite.cfg.in" "!GSDLHOME!\llssite.cfg"
|
---|
[20391] | 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:
|
---|
[24829] | 131 | echo !CLASSPATH!
|
---|
[20391] | 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:
|
---|
[24829] | 175 | echo "!GSDLHOME!\etc\logs-gsi\server.log"
|
---|
[20896] | 176 | echo.
|
---|
| 177 | echo Using Apache web server located at:
|
---|
[24829] | 178 | echo "!GSDLHOME!\apache-httpd\!GSDLOS!\bin\httpd"
|
---|
[20896] | 179 | echo The Apache error log is at:
|
---|
[24829] | 180 | echo "!GSDLHOME!\apache-httpd\!GSDLOS!\logs\error_log"
|
---|
[20896] | 181 | echo The Apache configuration file template is at:
|
---|
[24829] | 182 | echo "!GSDLHOME!\apache-httpd\!GSDLOS!\conf\httpd.conf.in"
|
---|
[20896] | 183 | echo This is used to generate:
|
---|
[24829] | 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:
|
---|
[24508] | 192 | :: cmd /c start "window" "c:\path to\gs2-web-server.bat" --config=c:\path to\llssite.cfg --quit=portnum --mode=gli
|
---|
[24492] | 193 | :: where the --options are generally optional, but always used for GLI.
|
---|
[21966] | 194 | :: The configfile param could contain spaces, in which case its space-separated parts spread over
|
---|
[24492] | 195 | :: multiple parameters. In the past, we used to handle this problem here.
|
---|
| 196 | :: At present we pass all the arguments as-is to the Server.jar program and let it handle the parameters.
|
---|
[24508] | 197 | :: E.g. gs2-web-server.bat --config=C:\pinky was\here at greenstone2\llssite.cfg --mode=gli --quitport=50100
|
---|
| 198 | :: or gs2-web-server.bat --quitport=50100 --config=C:\pinky was\here at greenstone2\llssite.cfg --mode=gli
|
---|
[24492] | 199 | :: Note the (lack of) use of quotes!
|
---|
[21966] | 200 |
|
---|
[22084] | 201 |
|
---|
[21966] | 202 | :runit
|
---|
[23987] | 203 | :: whenever the server is started up, make sure gsdlhome is correct (in case the gs install was moved).
|
---|
| 204 | :: In parallel with the linux equivalent script, redirect stdout into the void
|
---|
| 205 | :: (If redirecting both stderr and stdout into the void, would need to use >nul 2>&1. See
|
---|
| 206 | :: http://stackoverflow.com/questions/1420965/redirect-stdout-and-stderr-to-a-single-file-in-dos)
|
---|
| 207 | call gsicontrol.bat reset-gsdlhome >nul
|
---|
| 208 |
|
---|
[21966] | 209 | ::echo port: %port%& echo conf: %conf%& echo.& echo.
|
---|
[24492] | 210 | :: Do not remove the quotes around %* !!! It's what helps Server2.jar deal with spaces in configfile path
|
---|
[24874] | 211 | if not defined GSDLARCH "%JAVA_EXECUTABLE%" org.greenstone.server.Server2 "%GSDLHOME%" "%GSDLOS%" "%serverlang%" "%*"
|
---|
| 212 | if defined GSDLARCH "%JAVA_EXECUTABLE%" org.greenstone.server.Server2 "%GSDLHOME%" "%GSDLOS%%GSDLARCH%" "%serverlang%" "%*"
|
---|
[21966] | 213 |
|
---|
[24492] | 214 | :: All params are stored in %* now. This batch script can be called from the commandline or from GLI
|
---|
| 215 | :: If the --mode(=gli) flag was passed in as parameter, then this script was launched through GLI
|
---|
| 216 | :: and would have opened a DOS console. Need to then exit from this script to close the console.
|
---|
| 217 | set allparams=%*
|
---|
| 218 | :: And if there were absolutely no params to gs2-web-server.bat, it's not called from GLI either
|
---|
| 219 | if "%allparams%" == "" goto exit
|
---|
| 220 | set glimode=%allparams:--mode=%
|
---|
| 221 | :: if one of the parameters was --mode(=gli), we close the console
|
---|
| 222 | if /i "%allparams%" == "%glimode%" (
|
---|
| 223 | goto exit
|
---|
| 224 | ) else (
|
---|
| 225 | goto quitcmd
|
---|
| 226 | )
|
---|
[20391] | 227 |
|
---|
[20478] | 228 | :: Exit the batch script (close the console)
|
---|
| 229 | :quitcmd
|
---|
| 230 | popd
|
---|
| 231 | ENDLOCAL
|
---|
| 232 | exit 0
|
---|
| 233 |
|
---|
| 234 | :: Just end the script without closing the console
|
---|
[20391] | 235 | :exit
|
---|
| 236 | popd
|
---|
| 237 | ENDLOCAL
|
---|