source: gsdl/trunk/gsicontrol.bat@ 20184

Last change on this file since 20184 was 20184, checked in by ak19, 15 years ago

The program that sends the Stop signal to the apache web server now takes an additional parameter: SILENT. If provided, it will not display a popup if the handle is invalid (if there was no apache web server running).

File size: 6.4 KB
Line 
1@echo off
2
3setlocal
4set testdone=0
5set target=%1
6set configfile=%2
7
8:: Need to get greenstone installation directory
9:: set cwd=%CD%
10
11set MONITOR_SUCCESS=MAKE SUCCESSFUL
12set MONITOR_FAILED=MAKE FAILED
13set MONITOR_FINISHED=MAKE DONE
14
15:: check that we have >=1 and <=2 arguments
16:chkargs
17if "%target%" == "" goto :usage
18if not "%3" == "" goto :usage
19 goto begincmd
20
21
22:usage
23echo.
24echo Usage: %0 command
25echo where command is any of the following:
26echo web-start
27echo web-stop
28echo web-restart
29echo configure-admin
30echo configure-web [config-filename]
31echo configure-apache [config-filename]
32echo configure-cgi
33
34::echo web-status
35::echo web-graceful
36::echo test-gsdlhome
37::echo web-stop-tested
38echo.
39goto exit
40
41
42:begincmd
43:: web-stop-tested command assumes GSDLHOME/greenstone environment is already set
44if "%target%" == "web-stop-tested" goto stoptest
45
46:: For all other commands, the greenstone environment needs to be set first before they can be run
47:testgsdl
48if NOT "%GSDLHOME%" == "" if NOT "%GSDLOS%" == "" goto commands
49 echo.
50 echo Environment variable GSDLHOME (or GSDLOS) not set.
51 echo This needs to be set to run the gsicontrol command %target%.
52 echo Have you run setup.bat?
53 echo.
54 goto exit
55
56
57::MAIN MENU
58:commands
59if "%target%" == "web-start" goto start
60if "%target%" == "web-stop" goto stop
61if "%target%" == "web-restart" goto restart
62if "%target%" == "web-status" goto status
63if "%target%" == "web-graceful" goto graceful
64if "%target%" == "configure-admin" goto cfgadmin
65if "%target%" == "configure-web" goto cfgweb
66if "%target%" == "configure-apache" goto cfgapach
67if "%target%" == "configure-cgi" goto cfgcgi
68if "%target%" == "test-gsdlhome" goto testgsdl
69if "%target%" == "portcon" goto portcon1
70 :: unknown command
71 goto usage
72
73:start
74:: START starts the app in a new console named by the string following immediately thereafter
75:: then we start up apache-httpd and pass the signal that the stop command will respond to
76START "%GSDLHOME%\apachectl" "%GSDLHOME%\bin\windows\starthttpd.exe" GS2_APACHE_HTTPD "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
77echo %MONITOR_SUCCESS%
78echo %MONITOR_FINISHED%
79goto exit
80
81:stop
82if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD
83rem if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\apache-httpd\%GSDLOS%\bin\apachectl" stop
84echo %MONITOR_SUCCESS%
85echo %MONITOR_FINISHED%
86goto exit
87
88:restart
89if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD
90:: wait 2s, see http://malektips.com/dos0017.html. The 2 in the 2nd line is variable
91ping 127.0.0.1 -n 2 -w 1000 > nul
92ping 127.0.0.1 -n 2 -w 1000> nul
93::"%GSDLHOME%\bin\windows\starthttpd.exe" GS2_APACHE_HTTPD "%GSDLHOME%\apache-httpd\windows\bin\httpd.exe"
94goto start
95
96:status
97:graceful
98::echo Command %target% is not yet operational (no local apache web server included in this release).
99goto exit
100
101:stoptest
102if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD
103rem if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\apache-httpd\%GSDLOS%\bin\apachectl" stop
104goto exit
105
106::configure-web
107::configure-cgi
108:cfgweb
109:cfgcgi
110if exist "%GSDLHOME%\cgi-bin\gsdlsite.cfg" goto cgimsg
111 echo Configuring cgi-bin\gsdlsite.cfg
112 set gsdlpath=%GSDLHOME%
113 for /F "delims=*" %%T in ('"echo %gsdlpath%| bin\windows\sed.exe s@\\@\\\\@g"') do set safepath=%%T
114 bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg
115 set gsdlpath=
116 set safepath=
117 goto cgifin
118
119:cgimsg
120echo WARNING: Nothing done for make configure-cgi.
121echo If you wish to regenerate the file
122echo %GSDLHOME%\cgi-bin\gsdlsite.cfg
123echo from scratch, delete the existing file first.
124echo.
125
126:cgifin
127if "%target%" == "configure-cgi" goto exit
128if "%target%" == "configure-web" goto cfgapach
129
130::configure-apache
131:cfgapach
132if exist "%GSDLHOME%\llssite.cfg" goto :exit
133if not exist "%GSDLHOME%\llssite.cfg.in" goto :exit
134 copy llssite.cfg.in llssite.cfg
135 set configfile="%GSDLHOME%\llssite.cfg"
136 goto exit
137
138::configure-admin
139:cfgadmin
140echo.
141echo Configuring admin user password:
142for /F %%T in ('getpw') do set encrypted_password=%%T
143
144:: Have to create an intermediate file in the following, because echoing
145:: lines straight into a pipe adds spaces before the end of each line.
146:: When piping, need to double-escape the angle brackets with three hat signs,
147:: but when redirecting to a file, need to escape only once (one hat sign).
148if ERRORLEVEL 0 (
149 (
150 echo [admin]
151 echo ^<enabled^>true
152 echo ^<groups^>administrator,colbuilder,all-collections-editor
153 echo ^<password^>%encrypted_password%
154 echo ^<username^>admin
155 ) > "%GSDLHOME%\etc\users.txt"
156 type "%GSDLHOME%\etc\users.txt" | txt2db -append "%GSDLHOME%\etc\users.gdb"
157 del "%GSDLHOME%\etc\users.txt"
158) else (
159 echo Did not set password
160)
161goto exit
162
163::configure-port-and-connection
164:portcon1
165set /p port=Enter port number to use:
166set /p connect=Allow external connections [yes/no]:
167if "%connect%" == "yes" set allowfrom="all" goto portcon2
168if "%connect%" == "y" set allowfrom="all" goto portcon2
169set allowfrom="127.0.0.1"
170
171:portcon2
172if "%port%" == "" goto exit
173 set _sed="bin\windows\sed.exe"
174 set gsdlpath=%GSDLHOME%
175 for /F "delims=*" %%T in ('"echo %gsdlpath%| bin\windows\sed.exe s@\\@\/@g"') do set safepath=%%T
176
177 echo Port: %port%
178 echo Stopping web server (if running)
179 if not exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" echo missing conf file
180 if exist "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf" "%GSDLHOME%\bin\windows\stophttpd.exe" GS2_APACHE_HTTPD SILENT
181 echo Setting config file to use port %port%
182bin\windows\sed.exe "s@\*\*GSDLHOME\*\*@\"%safepath%\"@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg
183 type "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf.in" | %_sed% "s@\*\*PORT\*\*@%port%@g" | %_sed% "s@\*\*CONNECTION\*\*@%allowfrom%@g" | %_sed% "s@\*\*GSDLHOME\*\*@%safepath%@g" | %_sed% "s@\*\*APACHE_HOME_OS\*\*@%safepath%\/apache-httpd\/%GSDLOS%@g" > "%GSDLHOME%\apache-httpd\%GSDLOS%\conf\httpd.conf"
184 echo Type '%0 web-start' to start the web server running on port %port%
185 echo Done
186 set port=
187 set connect=
188 set allowfrom=
189 set _sed=
190 set safepath=
191 set gsdlpath=
192
193
194:exit
195endlocal
Note: See TracBrowser for help on using the repository browser.