source: gsdl/trunk/gsicontrol.bat@ 20637

Last change on this file since 20637 was 20637, checked in by ak19, 15 years ago
  1. Many changes to gsicontrol.bat to bring it up to date with the recent changes made to gsicontrol.sh. The httpd.conf.in now has a HOST_IP placeholder instead of HOSTS for the Allow From line. Now the httpd.conf always has at least the home IP (127.0.0.1) as well as the hostIP we write. These ensure that the local URLs localhost and hostname work on Linux and Windows. Other changes: the restart label is implemented differently and other minor corrections. 2. Minor spelling correction to gsicontrol.sh
File size: 8.3 KB
Line 
1@echo off
2
3setlocal
4::set testdone=0
5set target=%1
6set configfile=%2
7
8:: Construct the signal using the unique GS2 installation
9:: directory (after replacing colons and backslashes)
10for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@[\\:]@_@g"') do set signal=%%T
11set GS2_APACHE_HTTPD_SIGNAL=GS2_APACHE_HTTPD_%signal%
12rem echo Signal is: %GS2_APACHE_HTTPD_SIGNAL%
13
14:: Need to get greenstone installation directory
15:: set cwd=%CD%
16
17set MONITOR_SUCCESS=MAKE SUCCESSFUL
18set MONITOR_FAILED=MAKE FAILED
19set MONITOR_FINISHED=MAKE DONE
20
21:: check that we have >=1 and <=2 arguments
22:chkargs
23if "%target%" == "" goto usage
24if not "%3" == "" goto usage
25 goto begincmd
26
27
28:usage
29echo.
30echo Usage: %0 command
31echo where command is any of the following:
32echo web-start
33echo web-stop
34echo web-restart
35::echo web-status
36::echo web-graceful
37echo configure-admin
38echo configure-web [config-filename]
39echo configure-apache [config-filename]
40echo configure-cgi
41echo set-port
42echo test-gsdlhome
43echo web-stop-tested
44echo.
45goto exit
46
47
48:begincmd
49:: web-stop-tested command assumes GSDLHOME/greenstone environment is already set
50if "%target%" == "web-stop-tested" goto stoptest
51
52:: For all other commands, the greenstone environment needs to be set first before they can be run
53:testgsdl
54if NOT "%GSDLHOME%" == "" if NOT "%GSDLOS%" == "" goto commands
55echo.
56echo Environment variable GSDLHOME (or GSDLOS) not set.
57echo This needs to be set to run the gsicontrol command %target%.
58echo Have you run setup.bat?
59echo.
60goto exit
61
62
63::MAIN MENU
64:commands
65echo.
66echo Using:
67echo GSDLHOME = %GSDLHOME%
68echo GSDLOS = %GSDLOS%
69echo.
70
71if "%target%" == "web-start" goto start
72if "%target%" == "web-stop" goto stop
73if "%target%" == "web-restart" goto restart
74if "%target%" == "configure-admin" goto cfgadmin
75if "%target%" == "configure-web" goto cfgweb
76if "%target%" == "configure-apache" goto cfgapach
77if "%target%" == "configure-cgi" goto cfgcgi
78:: already tested gsdlhome (and web-stop-tested) above, don't want to keep looping on it
79if "%target%" == "test-gsdlhome" goto exit
80rem if "%target%" == "web-stop-tested" goto exit
81rem if "%target%" == "web-status" goto status
82rem if "%target%" == "web-graceful" goto graceful
83if "%target%" == "set-port" goto setport
84:: unknown command
85echo Command unrecognised: %target%
86goto usage
87
88
89:start
90:: START starts the app in a new console named by the string following immediately thereafter
91:: then we start up apache-httpd and pass the signal that the stop command will respond to
92START "%GSDLHOME%\apachectl" "%GSDLHOME%\bin\windows\starthttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
93echo %MONITOR_SUCCESS%
94echo %MONITOR_FINISHED%
95goto exit
96
97:stop
98:stoptest
99if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
100if "%target%" == "web-stop-tested" goto exit
101echo %MONITOR_SUCCESS%
102echo %MONITOR_FINISHED%
103goto exit
104
105
106:restart
107:: Need to stop server, wait and start it again.
108:: We're using Ping to implement batch file Wait
109if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL%
110
111:: Wait 5 seconds and then start. See http://ss64.com/nt/sleep.html (and http://malektips.com/dos0017.html)
112:: if loopback IP address (127.0.0.1) does not exist, we ask them to manually start it up again
113ping -n 1 -w 1000 127.0.0.1 |find "TTL=">nul || goto failmsg
114echo Waiting for re-start....
115ping -n 5 -w 1000 127.0.0.1> nul
116goto start
117
118:failmsg
119echo Unable to wait for restart. Manually run %0 web-start
120goto exit
121
122
123::status
124::graceful
125::echo Command %target% is not operational on this operating system
126::goto exit
127
128
129::configure-admin
130:cfgadmin
131echo.
132echo Configuring admin user password:
133for /F %%T in ('getpw') do set encrypted_password=%%T
134
135:: Have to create an intermediate file in the following, because echoing
136:: lines straight into a pipe adds spaces before the end of each line.
137:: When piping, need to double-escape the angle brackets with three hat signs,
138:: but when redirecting to a file, need to escape only once (one hat sign).
139if ERRORLEVEL 0 (
140 (
141 echo [admin]
142 echo ^<enabled^>true
143 echo ^<groups^>administrator,colbuilder,all-collections-editor
144 echo ^<password^>%encrypted_password%
145 echo ^<username^>admin
146 ) > "%GSDLHOME%\etc\users.txt"
147 type "%GSDLHOME%\etc\users.txt" | txt2db -append "%GSDLHOME%\etc\users.gdb"
148 del "%GSDLHOME%\etc\users.txt"
149) else (
150 echo Did not set password
151)
152echo.
153goto exit
154
155
156::configure-web
157::configure-cgi
158:cfgweb
159:cfgcgi
160if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg
161echo Configuring cgi-bin\gsdlsite.cfg
162for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\\\\@g"') do set safepath=%%T
163bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg
164set safepath=
165goto cgifin
166
167:cgimsg
168echo WARNING: Nothing done for configure-cgi.
169echo If you wish to regenerate the file
170echo %GSDLHOME%\cgi-bin\gsdlsite.cfg
171echo from scratch, delete the existing file first.
172echo.
173
174:cgifin
175if "%target%" == "configure-cgi" goto exit
176if "%target%" == "configure-web" goto cfgapach
177
178::configure-apache
179:cfgapach
180if not "%configfile%" == "" if exist "%configfile%" (goto cfgport) else (echo Config file %configfile% does not exist. Using default llssite.cfg)
181
182if exist "%GSDLHOME%\llssite.cfg" (
183 set configfile="%GSDLHOME%\llssite.cfg"
184 goto cfgport
185)
186if not exist "%GSDLHOME%\llssite.cfg.in" (
187 echo Unable to proceed as neither %GSDLHOME%\llssite.cfg nor %GSDLHOME%\llssite.cfg.in could be found
188 goto exit
189)
190copy "%GSDLHOME%\llssite.cfg.in" "%GSDLHOME%\llssite.cfg"
191set configfile="%GSDLHOME%\llssite.cfg"
192
193:cfgport
194echo Configuring the apache webserver...
195:: See http://ss64.com/nt/for_cmd.html, http://ss64.com/nt/findstr.html (and http://ss64.com/nt/find.html)
196FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^portnumber %configfile%') do set port=%%G
197FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^hostIP %configfile%') do set hostIP=%%G
198FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^externalaccess %configfile%') do set allowfromall=%%G
199
200if "%allowfromall%" == "1" set allowfromall="Allow"& goto portcon
201set allowfromall="Deny"
202
203:: Using CALL to jump to labels means we can return from them. BUT need to ensure
204:: that command extensions are enabled to call labels. So just use GOTO instead.
205::http://ss64.com/nt/call.html
206goto portcon
207
208
209::configure-port-and-connection
210:setport
211set /p port=Enter port number to use:
212set /p hostIP=Enter host IP to allow (127.0.0.1 is included by default):
213set /p allowfromall=Allow external connections [yes/no]:
214
215if "%allowfromall%" == "yes" set allowfromall="Allow"& goto portcon
216if "%allowfromall%" == "y" set allowfromall="Allow"& goto portcon
217set allowfromall="Deny"
218goto portcon
219
220:portcon
221if "%port%" == "" (
222 echo Done
223 goto exit
224)
225set _sed="bin\windows\sed.exe"
226for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
227
228echo Port: %port%
229echo Stopping web server (if running)
230if not exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo Missing conf file
231if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
232echo Setting config file to use port %port%
233type "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf.in" | %_sed% "s@\*\*PORT\*\*@%port%@g" | %_sed% "s@\*\*CONNECTPERMISSION\*\*@%allowfromall%@g" | %_sed% "s@\*\*HOST_IP\*\*@%hostIP%@g" | %_sed% "s@\*\*GSDLHOME\*\*@%safepath%@g" | %_sed% "s@\*\*APACHE_HOME_OS\*\*@%safepath%\/apache-httpd\/%GSDLOS%@g" > "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf"
234echo Type '%0 web-start' to start the web server running on port %port%
235echo Done
236
237set allowfromall=
238set _sed=
239set safepath=
240set port=
241
242:: Extra processing for configure-web and configure-cgi command targets
243if not "%target%" == "configure-web" if not "%target%" == "configure-cgi" goto exit
244if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
245echo %MONITOR_FINISHED%
246goto exit
247
248:exit
249endlocal
Note: See TracBrowser for help on using the repository browser.