source: gsdl/trunk/gs2-server.bat@ 20901

Last change on this file since 20901 was 20901, checked in by ak19, 14 years ago

Silly mistakes in the display that I introduced during the previous commit. Corrected now.

File size: 5.7 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)
26echo GS2 Home: %GSDLHOME%
27
28:: Setup Greenstone2, unless it has already been done
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
31for %%i in ("%GSDLOS%" "%GSDLHOME%") do if %%i == "" set OR=True
32if "%OR%" == "True" (
33 pushd "%gsdl2path%"
34 call setup.bat
35rem echo **** GSDLOS: %GSDLOS% and GSDLHOME: %GSDLHOME%
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."
48::echo %GSDLHOME%\apache-httpd\nul
49if not exist %GSDLHOME%\apache-httpd\nul (
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
61if exist "%GSDLHOME%\llssite.cfg" goto cfgfile
62if 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
71bin\windows\search4j -m %java_min_version% > nul
72echo.
73:: In Java code, '...getResourceAsStream("build.properties")'
74:: needs up to be in the right directory when run
75if %ERRORLEVEL% equ 0 pushd %GSDL2PATH%
76
77:: http://ss64.com/nt/call.html (and leave in trailing slash)
78call :isinpath %GSDLHOME%\lib\java
79
80:: After the call, we come back here
81goto chkjava
82
83:isinpath
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")
86:: Instead, we expand the filepath of parameter 1 to its full path and
87:: try to subtract it from the classpath.
88::call set test_cpath=%%CLASSPATH:%~f1=%%
89call set test_cpath=%%CLASSPATH:%1=%%
90
91:: If there IS a difference in the classpath before and after,
92:: then the filepath was already on the classpath
93if not "%CLASSPATH%" == "%test_cpath%" (
94 echo - CLASSPATH already correct
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
101set CLASSPATH=%GSDLHOME%\lib\java;%CLASSPATH%
102
103:: http://ss64.com/nt/for_r.html and (for call) http://ss64.com/nt/for.html
104:: http://ss64.com/nt/syntax-args.html
105FOR /R "%GSDLHOME%\lib\java" %%G IN (*.jar) DO call :putinpath %%G
106echo - Adjusted CLASSPATH
107echo.
108::echo CLASSPATH:& echo %CLASSPATH%
109goto :eof
110
111
112:putinpath
113echo jarfile: %1
114set CLASSPATH=%CLASSPATH%;%1
115goto :eof
116
117:: ---- Check Java ----
118:chkjava
119:: call the script with source, so that we have the variables JAVA_EXECUTABLE and GS_JAVA_HOME it sets
120set exit_status=0
121:: Need to find Java. If found, JAVA_EXECUTABLE will be set
122:: call findjava.bat %serverlang% %PROGNAME%
123call "%GSDLHOME%\findjava.bat"
124if "%JAVA_EXECUTABLE%" == "" echo **** No Java executable found& goto exit
125set PATH=%GS_JAVA_HOME%\bin;%PATH%
126
127
128:: ---- Run the Greenstone Server Interface ----
129:: Some informative messages to direct the users to the logs
130if "%serverlang%" == "en" (
131 echo ***************************************************************
132 echo Starting the Greenstone Server Interface (GSI)...
133 echo.
134 echo Server log messages go to:
135 echo %GSDLHOME%\etc\logs-gsi\server.log
136 echo.
137 echo Using Apache web server located at:
138 echo %GSDLHOME%\apache-httpd\%GSDLOS%\bin\httpd
139 echo The Apache error log is at:
140 echo %GSDLHOME%\apache-httpd\%GSDLOS%\logs\error_log
141 echo The Apache configuration file template is at:
142 echo %GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf.in
143 echo This is used to generate:
144 echo %GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf
145 echo each time Enter Library is pressed or otherwise activated.
146 echo ***************************************************************
147 echo.
148)
149echo.
150"%JAVA_EXECUTABLE%" org.greenstone.server.Server2 "%GSDLHOME%" "%serverlang%" %*
151::echo ******* Second argument to gs2-server.bat is: %2
152:: The 1st argument to gs2-server.bat (if any) would be --config, the 2nd is the config
153:: filename if it is glisite.cfg, then this script was launched through GLI and would
154:: have opened a DOS console. Need to exit from this script then to close the console.
155if "%2" == "%GSDLHOME%\glisite.cfg" goto quitcmd
156goto exit
157
158:: Exit the batch script (close the console)
159:quitcmd
160popd
161ENDLOCAL
162exit 0
163
164:: Just end the script without closing the console
165:exit
166popd
167ENDLOCAL
Note: See TracBrowser for help on using the repository browser.