source: gsdl/trunk/gsicontrol.bat@ 20639

Last change on this file since 20639 was 20639, checked in by ak19, 15 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.

File size: 8.5 KB
RevLine 
[19278]1@echo off
2
[19970]3setlocal
[20262]4::set testdone=0
[19278]5set target=%1
6set configfile=%2
7
[20262]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
[19970]14:: Need to get greenstone installation directory
15:: set cwd=%CD%
[19278]16
[19970]17set MONITOR_SUCCESS=MAKE SUCCESSFUL
18set MONITOR_FAILED=MAKE FAILED
19set MONITOR_FINISHED=MAKE DONE
20
[19278]21:: check that we have >=1 and <=2 arguments
22:chkargs
[20262]23if "%target%" == "" goto usage
24if not "%3" == "" goto usage
[19278]25 goto begincmd
26
27
28:usage
29echo.
30echo Usage: %0 command
31echo where command is any of the following:
[19970]32echo web-start
33echo web-stop
34echo web-restart
[20262]35::echo web-status
36::echo web-graceful
[19278]37echo configure-admin
38echo configure-web [config-filename]
39echo configure-apache [config-filename]
40echo configure-cgi
[20637]41echo set-port
[20262]42echo test-gsdlhome
43echo web-stop-tested
[19278]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
[20159]54if NOT "%GSDLHOME%" == "" if NOT "%GSDLOS%" == "" goto commands
[20338]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
[19278]61
62
63::MAIN MENU
64:commands
[20262]65echo.
66echo Using:
67echo GSDLHOME = %GSDLHOME%
68echo GSDLOS = %GSDLOS%
69echo.
70
[19278]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
[20262]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
[20338]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
[19278]87
[20338]88
[19278]89:start
[20159]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
[20262]92START "%GSDLHOME%\apachectl" "%GSDLHOME%\bin\windows\starthttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
[20639]93:: if the return value is >= 0, it's succeeded:
94if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
[19970]95echo %MONITOR_FINISHED%
96goto exit
97
[19278]98:stop
[20262]99:stoptest
[20435]100if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL% SILENT
[20262]101if "%target%" == "web-stop-tested" goto exit
[20639]102:: if the return value is >= 0, it's succeeded:
103if ERRORLEVEL 0 (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
[20262]104echo %MONITOR_FINISHED%
[19970]105goto exit
106
[20637]107
[19278]108:restart
[20637]109:: Need to stop server, wait and start it again.
110:: We're using Ping to implement batch file Wait
[20262]111if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" %GS2_APACHE_HTTPD_SIGNAL%
[20637]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
[19970]118goto start
119
[20637]120:failmsg
121echo Unable to wait for restart. Manually run %0 web-start
122goto exit
123
124
[20338]125::status
126::graceful
127::echo Command %target% is not operational on this operating system
128::goto exit
[19278]129
130
131::configure-admin
132:cfgadmin
133echo.
[19288]134echo Configuring admin user password:
135for /F %%T in ('getpw') do set encrypted_password=%%T
[19290]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.
[19970]139:: When piping, need to double-escape the angle brackets with three hat signs,
[19290]140:: but when redirecting to a file, need to escape only once (one hat sign).
[19288]141if ERRORLEVEL 0 (
142 (
143 echo [admin]
[19290]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"
[19288]151) else (
152 echo Did not set password
153)
[20262]154echo.
[19288]155goto exit
[19278]156
[20338]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
[20637]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
[20338]201
[20637]202if "%allowfromall%" == "1" set allowfromall="Allow"& goto portcon
203set allowfromall="Deny"
[20615]204
[20338]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
[20637]210
[19970]211::configure-port-and-connection
[20338]212:setport
[19970]213set /p port=Enter port number to use:
[20637]214set /p hostIP=Enter host IP to allow (127.0.0.1 is included by default):
215set /p allowfromall=Allow external connections [yes/no]:
[20338]216
[20637]217if "%allowfromall%" == "yes" set allowfromall="Allow"& goto portcon
218if "%allowfromall%" == "y" set allowfromall="Allow"& goto portcon
219set allowfromall="Deny"
[20615]220goto portcon
221
[20338]222:portcon
223if "%port%" == "" (
[20505]224 echo Done
225 goto exit
[20338]226)
227set _sed="bin\windows\sed.exe"
228for /F "delims=*" %%T in ('"echo %GSDLHOME%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
[19970]229
[20338]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%
[20637]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"
[20338]236echo Type '%0 web-start' to start the web server running on port %port%
237echo Done
[19970]238
[20637]239set allowfromall=
[20338]240set _sed=
241set safepath=
[20637]242set port=
[20338]243
244:: Extra processing for configure-web and configure-cgi command targets
[20637]245if not "%target%" == "configure-web" if not "%target%" == "configure-cgi" goto exit
[20338]246if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" (echo %MONITOR_SUCCESS%) else (echo %MONITOR_FAILED%)
247echo %MONITOR_FINISHED%
248goto exit
249
[19278]250:exit
[19970]251endlocal
Note: See TracBrowser for help on using the repository browser.