root/gsdl/trunk/gsicontrol.bat @ 20639

Revision 20639, 8.5 KB (checked in by ak19, 10 years ago)

Now, on web-start and web-stop, the gsicontrol.bat script no longer automatically returns MONITOR_SUCCESS. If the errorlevel value returned from the stophttpd and starthttpd executables are negative, MONITOR_FAILED is returned. Only if errorlevel is 0 or higher, is MONITOR_SUCCESS returned. Modified the starthttpd (and starthttpdchild) and stophttpd cpp files to return a -1 when the number of arguments are wrong.

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"
93:: if the return value is >= 0, it's succeeded:
94if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
95echo %MONITOR_FINISHED%
96goto exit
97
98:stop
99:stoptest
100if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
101if "%target%" == "web-stop-tested" goto exit
102:: if the return value is >= 0, it's succeeded:
103if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
104echo %MONITOR_FINISHED%
105goto exit
106
107
108:restart
109:: Need to stop server, wait and start it again.
110:: We're using Ping to implement batch file Wait
111if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL%
112
113:: Wait 5 seconds and then start. See http://ss64.com/nt/sleep.html (and http://malektips.com/dos0017.html)
114:: if loopback IP address (127.0.0.1) does not exist, we ask them to manually start it up again
115ping -n 1 -w 1000 127.0.0.1 |find "TTL=">nul || goto failmsg
116echo Waiting for re-start....
117ping -n 5 -w 1000 127.0.0.1> nul
118goto start
119
120:failmsg
121echo Unable to wait for restart. Manually run %0 web-start
122goto exit
123
124
125::status
126::graceful
127::echo Command %target% is not operational on this operating system
128::goto exit
129
130
131::configure-admin
132:cfgadmin
133echo.
134echo Configuring admin user password:
135for /F %%T in ('getpw') do set encrypted_password=%%T
136
137:: Have to create an intermediate file in the following, because echoing
138:: lines straight into a pipe adds spaces before the end of each line.
139:: When piping, need to double-escape the angle brackets with three hat signs,
140:: but when redirecting to a file, need to escape only once (one hat sign).
141if ERRORLEVEL 0 (
142    (
143    echo [admin]
144    echo ^<enabled^>true
145    echo ^<groups^>administrator,colbuilder,all-collections-editor
146    echo ^<password^>%encrypted_password%
147    echo ^<username^>admin
148    ) > "%GSDLHOME%\etc\users.txt"
149    type "%GSDLHOME%\etc\users.txt" | txt2db -append "%GSDLHOME%\etc\users.gdb"
150    del "%GSDLHOME%\etc\users.txt" 
151) else (
152    echo Did not set password
153)
154echo.
155goto exit
156
157
158::configure-web
159::configure-cgi
160:cfgweb
161:cfgcgi
162if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg
163echo Configuring cgi-bin\gsdlsite.cfg
164for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\\\\@g"') do set safepath=%%T
165bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg   
166set safepath=
167goto cgifin
168
169:cgimsg
170echo WARNING: Nothing done for configure-cgi.
171echo    If you wish to regenerate the file
172echo    %GSDLHOME%\cgi-bin\gsdlsite.cfg
173echo    from scratch, delete the existing file first.
174echo.
175
176:cgifin
177if "%target%" == "configure-cgi" goto exit
178if "%target%" == "configure-web" goto cfgapach
179
180::configure-apache
181:cfgapach
182if not "%configfile%" == "" if exist "%configfile%" (goto cfgport) else (echo Config file %configfile% does not exist. Using default llssite.cfg)
183
184if exist "%GSDLHOME%\llssite.cfg" (
185  set configfile="%GSDLHOME%\llssite.cfg"
186  goto cfgport
187)
188if not exist "%GSDLHOME%\llssite.cfg.in" (
189  echo Unable to proceed as neither %GSDLHOME%\llssite.cfg nor %GSDLHOME%\llssite.cfg.in could be found
190  goto exit
191)
192copy "%GSDLHOME%\llssite.cfg.in" "%GSDLHOME%\llssite.cfg"
193set configfile="%GSDLHOME%\llssite.cfg"
194
195:cfgport
196echo Configuring the apache webserver...
197:: See http://ss64.com/nt/for_cmd.html, http://ss64.com/nt/findstr.html (and http://ss64.com/nt/find.html)
198FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^portnumber %configfile%') do set port=%%G
199FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^hostIP %configfile%') do set hostIP=%%G
200FOR /F "tokens=2 delims==" %%G IN ('findstr /R ^externalaccess %configfile%') do set allowfromall=%%G
201
202if "%allowfromall%" == "1" set allowfromall="Allow"& goto portcon
203set allowfromall="Deny"
204
205:: Using CALL to jump to labels means we can return from them. BUT need to ensure
206:: that command extensions are enabled to call labels. So just use GOTO instead.
207::http://ss64.com/nt/call.html
208goto portcon
209
210
211::configure-port-and-connection
212:setport
213set /p port=Enter port number to use:
214set /p hostIP=Enter host IP to allow (127.0.0.1 is included by default):
215set /p allowfromall=Allow external connections [yes/no]:
216
217if "%allowfromall%" == "yes" set allowfromall="Allow"& goto portcon
218if "%allowfromall%" == "y" set allowfromall="Allow"& goto portcon
219set allowfromall="Deny"
220goto portcon
221
222:portcon
223if "%port%" == "" (
224   echo Done
225   goto exit
226)
227set _sed="bin\windows\sed.exe"
228for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
229
230echo Port: %port%
231echo Stopping web server (if running)
232if not exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo Missing conf file
233if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
234echo Setting config file to use port %port%
235type "%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"
236echo Type '%0 web-start' to start the web server running on port %port%
237echo Done
238
239set allowfromall=
240set _sed=
241set safepath=
242set port=
243
244:: Extra processing for configure-web and configure-cgi command targets
245if not "%target%" == "configure-web" if not "%target%" == "configure-cgi" goto exit
246if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
247echo %MONITOR_FINISHED%
248goto exit
249
250:exit
251endlocal
Note: See TracBrowser for help on using the browser.