1 | @echo off
|
---|
2 | SETLOCAL enabledelayedexpansion
|
---|
3 |
|
---|
4 | if "%serverlang%" == "" set serverlang=en
|
---|
5 | set java_min_version=1.5.0_00
|
---|
6 | set PROGNAME=gs2-server
|
---|
7 | if "%PROGABBR%" == "" set PROGABBR=GSI
|
---|
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 |
|
---|
27 | :checkUserPermissions
|
---|
28 | echo.
|
---|
29 | echo Checking if the Greenstone log directory is writable ...
|
---|
30 | if not exist "%GSDLHOME%\etc\logs-gsi" goto missingLogDir
|
---|
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
|
---|
38 | goto exit
|
---|
39 |
|
---|
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 |
|
---|
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 |
|
---|
61 | echo GS2 Home: %GSDLHOME%
|
---|
62 |
|
---|
63 | :: Setup Greenstone2, unless it has already been done
|
---|
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!"
|
---|
69 | call setup.bat
|
---|
70 | rem echo **** GSDLOS: %GSDLOS% and GSDLHOME: %GSDLHOME%
|
---|
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."
|
---|
83 | rem echo "%GSDLHOME%\apache-httpd\nul"
|
---|
84 | if not exist "%GSDLHOME%\apache-httpd\*" (
|
---|
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 |
|
---|
94 | set PATH=%GSDLHOME%\apache-httpd\windows\lib;%PATH%
|
---|
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)
|
---|
114 | call :isinpath "%GSDLHOME%\lib\java"
|
---|
115 |
|
---|
116 | :: After the call, we come back here
|
---|
117 | goto chkjava
|
---|
118 |
|
---|
119 | :isinpath
|
---|
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")
|
---|
122 | :: Instead, we expand the filepath of parameter 1 to its full path and
|
---|
123 | :: try to subtract it from the classpath.
|
---|
124 | ::call set test_cpath=%%CLASSPATH:%~f1=%%
|
---|
125 | call set test_cpath=%%CLASSPATH:%~1=%%
|
---|
126 |
|
---|
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:
|
---|
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 |
|
---|
139 | :: http://ss64.com/nt/for_r.html and (for call) http://ss64.com/nt/for.html
|
---|
140 | :: http://ss64.com/nt/syntax-args.html
|
---|
141 | FOR /R "%GSDLHOME%\lib\java" %%G IN (*.jar) DO call :putinpath "%%G"
|
---|
142 | echo - Adjusted CLASSPATH
|
---|
143 | echo.
|
---|
144 | ::echo CLASSPATH:& echo %CLASSPATH%
|
---|
145 | goto :eof
|
---|
146 |
|
---|
147 |
|
---|
148 | :putinpath
|
---|
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%
|
---|
154 | goto :eof
|
---|
155 |
|
---|
156 | :: ---- Check Java ----
|
---|
157 | :chkjava
|
---|
158 | :: call the script with source, so that we have the variables JAVA_EXECUTABLE and GS_JAVA_HOME it sets
|
---|
159 | set exit_status=0
|
---|
160 | :: Need to find Java. If found, JAVA_EXECUTABLE will be set
|
---|
161 | :: call findjava.bat %serverlang% %PROGNAME%
|
---|
162 | if "%GSDL3SRCHOME%" == "" (set _VERSION=2) else (set _VERSION=3)
|
---|
163 | call "%GSDLHOME%\findjava.bat"
|
---|
164 | if "%JAVA_EXECUTABLE%" == "" echo **** No Java executable found& goto exit
|
---|
165 | set PATH=%GS_JAVA_HOME%\bin;%PATH%
|
---|
166 |
|
---|
167 |
|
---|
168 | :: ---- Run the Greenstone Server Interface ----
|
---|
169 | :: Some informative messages to direct the users to the logs
|
---|
170 | if "%serverlang%" == "en" (
|
---|
171 | echo ***************************************************************
|
---|
172 | echo Starting the Greenstone Server Interface ^(GSI^)...
|
---|
173 | echo.
|
---|
174 | echo Server log messages go to:
|
---|
175 | echo "!GSDLHOME!\etc\logs-gsi\server.log"
|
---|
176 | echo.
|
---|
177 | echo Using Apache web server located at:
|
---|
178 | echo "!GSDLHOME!\apache-httpd\!GSDLOS!\bin\httpd"
|
---|
179 | echo The Apache error log is at:
|
---|
180 | echo "!GSDLHOME!\apache-httpd\!GSDLOS!\logs\error_log"
|
---|
181 | echo The Apache configuration file template is at:
|
---|
182 | echo "!GSDLHOME!\apache-httpd\!GSDLOS!\conf\httpd.conf.in"
|
---|
183 | echo This is used to generate:
|
---|
184 | echo "!GSDLHOME!\apache-httpd\!GSDLOS!\conf\httpd.conf"
|
---|
185 | echo each time Enter Library is pressed or otherwise activated.
|
---|
186 | echo ***************************************************************
|
---|
187 | echo.
|
---|
188 | )
|
---|
189 | echo.
|
---|
190 |
|
---|
191 | :: GLI launches gs2-server.bat with:
|
---|
192 | :: cmd /c start "window" "c:\path to\gs2-web-server.bat" --config=c:\path to\llssite.cfg --quit=portnum --mode=gli
|
---|
193 | :: where the --options are generally optional, but always used for GLI.
|
---|
194 | :: The configfile param could contain spaces, in which case its space-separated parts spread over
|
---|
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.
|
---|
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
|
---|
199 | :: Note the (lack of) use of quotes!
|
---|
200 |
|
---|
201 |
|
---|
202 | :runit
|
---|
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 |
|
---|
209 | ::echo port: %port%& echo conf: %conf%& echo.& echo.
|
---|
210 | :: Do not remove the quotes around %* !!! It's what helps Server2.jar deal with spaces in configfile path
|
---|
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%" "%*"
|
---|
213 |
|
---|
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 | )
|
---|
227 |
|
---|
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
|
---|
235 | :exit
|
---|
236 | popd
|
---|
237 | ENDLOCAL
|
---|