source: main/trunk/greenstone2/gs2-web-server.bat@ 22572

Last change on this file since 22572 was 22572, checked in by sjm84, 14 years ago

Renamed gs2-server.bat to gs2-web-server.bat and created a new script called gs2-server.bat that runs either the apache server (gs2-web-server.bat) or the local library server (server.exe) depending on whether or not server.exe exists

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