source: main/trunk/greenstone2/gsicontrol.sh@ 31861

Last change on this file since 31861 was 28576, checked in by ak19, 7 years ago

Apache-httpd on Mac Lion (and possible android systems where gnome-lib compiles up libiconv) is dependent on the libiconv dll located in the gnome-lib/OS/lib folder, so in such a case, we need to set up the (DY)LD_LIB_PATH environment before trying to stop or start the webserver.

  • Property svn:executable set to *
File size: 12.9 KB
Line 
1#!/bin/bash
2
3storedir="`pwd`"
4thisdir="`dirname \"$0\"`"
5thisdir="`cd \"$thisdir\" && pwd`"
6cd "$thisdir"
7source setup.bash
8
9testdone=0
10
11cgibin="cgi-bin"
12if [ -d "cgi-bin/$GSDLOS$GSDLARCH" ] ; then
13 cgibin="cgi-bin/$GSDLOS$GSDLARCH"
14fi
15
16
17function test-gsdlhome {
18 if [ $testdone == "0" ] ; then
19 if test -z "$GSDLHOME" ; then
20 echo "" ;
21 echo "Environment variable GSDLHOME not set." ;
22 echo " This needs to be set to run this gsicontrol command." ;
23 echo " Have you run 'source setup.bash'?" ;
24 echo "" ;
25 exit 1
26 else
27 echo "Using: " ;
28 echo " GSDLHOME = $GSDLHOME" ;
29 echo " GSDLOS = $GSDLOS" ;
30 fi
31 testdone=1
32 fi
33}
34
35function configure-cgi {
36 test-gsdlhome
37 if test ! -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
38 echo "Configuring $cgibin/gsdlsite.cfg" ;
39 echo "# **** This file is automatically generated, do not edit ****" > "$cgibin/gsdlsite.cfg" ;
40 echo "# For local customization of Greenstone, edit gsdlsite.cfg.in" >> "$cgibin/gsdlsite.cfg" ;
41 echo "" >> "$cgibin/gsdlsite.cfg" ;
42 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "$cgibin/gsdlsite.cfg.in" >> "$cgibin/gsdlsite.cfg" ;
43 else
44 echo "WARNING: Nothing done for make configure-cgi." ;
45 echo " If you wish to regenerate the file " ;
46 echo " $GSDLHOME/$cgibin/gsdlsite.cfg" ;
47 echo " from scratch, delete the existing file first." ;
48 fi
49}
50
51function configure-admin {
52 test-gsdlhome
53 echo "" ;
54 echo "Configuring admin user password:" ;
55 encrypted_password=`getpw` ;
56 if [ $? = "0" ] ; then
57 echo -e "[admin]\n<enabled>true\n<groups>administrator,colbuilder,all-collections-editor\n<password>$encrypted_password\n<username>admin" \
58 | txt2db -append "$GSDLHOME/etc/users.gdb" ;
59 else
60 echo "Did not set password" ;
61 fi
62 echo ""
63}
64
65
66function configure-port-and-connection {
67 test-gsdlhome
68
69 echo "Enter port number to use:"
70 read port ;
71 echo "Enter host IP to allow (127.0.0.1 is included by default):"
72 read hostIP ;
73 echo "Enter hostname or list of hosts to allow (localhost included by default):"
74 read hosts ;
75 echo "Allow external connections [yes/no]:"
76 read connection ;
77 if [ "x$connection" = "xyes" ] || [ "x$connection" = "xy" ] ; then
78 allowfromall="Allow"
79 else
80 allowfromall="Deny"
81 fi
82
83 lib_path_var="LD_LIBRARY_PATH" ;
84 if [ $GSDLOS = "darwin" ] ; then
85 lib_path_var="DYLD_LIBRARY_PATH"
86 fi
87
88 if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
89 collecthome=`egrep "^collecthome" "$GSDLHOME/$cgibin/gsdlsite.cfg" | awk '{print $2}'` ;
90 fi
91 if test -z $collecthome ; then
92 collecthome="$GSDLHOME/collect" ;
93 fi
94
95 if test ! -z $port ; then
96 echo "Port: $port" ;
97# if called by reset-gsdlhome, then httpd.conf file was regenerated by install-bindist.sh script and
98# contains placeholder strings, including for Listen port. So can't stop web-server in such a case.
99 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
100 confport=`egrep "^Listen" $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf | awk '{print $2}'` ;
101 if [ "$confport" != "**PORT**" ] ; then
102 echo "Stopping web server (if running)" ;
103 web-stop-tested ;
104 fi
105 fi
106 echo "Setting config file to use port $port";
107# Need to remove extra quotes around $collecthome. ${string//abc/xyz} does a replace all on abc with xyz
108 cat "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf.in" \
109 | sed "s@\*\*GSDL_OS_ARCH\*\*@$GSDLOS$GSDLARCH@g" \
110 | sed "s@\*\*PORT\*\*@$port@g" \
111 | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
112 | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
113 | sed "s@\*\*HOSTS\*\*@$hosts@g" \
114 | sed "s@\*\*COLLECTHOME\*\*@${collecthome//\"/}@g" \
115 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
116 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH@g" \
117 | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
118 > "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ;
119 echo "Type '$0 web-start' to start the web server running on port $port" ;
120 fi ;
121 echo "Done" ;
122}
123
124
125MONITOR_SUCCESS="MAKE SUCCESSFUL"
126MONITOR_FAILED="MAKE FAILED"
127MONITOR_FINISHED="MAKE DONE"
128
129function configure-apache {
130 test-gsdlhome
131 configfile=$1 ;
132# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
133 if [ "x$configfile" = "x" ]; then
134 if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
135 cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
136 fi
137 configfile="$GSDLHOME/llssite.cfg";
138 fi ;
139 echo "Configuring the apache webserver..." ;
140 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
141 hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
142 hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;
143
144 externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
145 if [ "x$externalaccess" = "x1" ] ; then
146 externalaccess="yes"
147 else
148 externalaccess="no"
149 fi
150
151 echo -e "$port\n$hostIP\n$hosts\n$externalaccess" | configure-port-and-connection ;
152 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
153 echo $MONITOR_SUCCESS;
154 else
155 echo $MONITOR_FAILED;
156 fi
157 echo $MONITOR_FINISHED
158}
159
160function configure-web {
161 for one_file in gs2-server.app gli.app client-gli.app gems.app ; do
162 if test -e "$one_file/Contents/document.wflow.in" ; then
163 if test ! -e "$one_file/Contents/document.wflow" ; then
164 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "$one_file/Contents/document.wflow.in" > "$one_file/Contents/document.wflow"
165 fi
166 fi
167 done ;
168
169 configure-cgi
170 configure-apache $1
171}
172
173# Forces configure-cgi by renaming gsdlsite.cfg
174# but only if we actually *need* to relocate gsdlhome.
175# We relocate at all times, except when there is a gsdlsite.cfg file with its
176# gsdlhome property the same as the current (greenstone installation) directory
177function reset-gsdlhome {
178 echo "" ;
179 relocate=yes ;
180
181# don't just update gsdlsite.cfg, but also the path to perl at the top of gliserver.pl and the other cgi-bin perl files
182# if this is a perl included with the Greenstone distribution
183 if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
184 stored_gsdlhome=`egrep "^gsdlhome" "$cgibin/gsdlsite.cfg" | awk '{print $2}'` ;
185 if [ "x$stored_gsdlhome" != "x$GSDLHOME" ]; then
186 /bin/mv "$GSDLHOME/$cgibin/gsdlsite.cfg" "$GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
187 echo "**** Regenerating $GSDLHOME/$cgibin/gsdlsite.cfg" ;
188 echo "**** Previous version of file now $GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
189
190 if test -d "$GSDLHOME/bin/$GSDLOS/perl" ; then
191 gliserverfile=$GSDLHOME/$cgibin/gliserver.pl ;
192 /bin/cp "$gliserverfile" "$gliserverfile.bak" ;
193 sed "s@$stored_gsdlhome@$GSDLHOME@g" "$gliserverfile.bak" > "$gliserverfile" ;
194 rm -f "$gliserverfile.bak" ;
195
196 metaserverfile=$GSDLHOME/$cgibin/metadata-server.pl ;
197 /bin/cp "$metaserverfile" "$metaserverfile.bak" ;
198 sed "s@$stored_gsdlhome@$GSDLHOME@g" "$metaserverfile.bak" > "$metaserverfile" ;
199 rm -f "$metaserverfile.bak" ;
200
201 checksumfile=$GSDLHOME/$cgibin/checksum.pl ;
202 /bin/cp "$checksumfile" "$checksumfile.bak" ;
203 sed "s@$stored_gsdlhome@$GSDLHOME@g" "$checksumfile.bak" > "$checksumfile" ;
204 rm -f "$checksumfile.bak" ;
205 fi
206
207 else
208 relocate=
209 fi
210 fi
211
212 if [ "x$relocate" = "xyes" ]; then
213 apache_home_os="$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH"
214
215 if test ! -e "$apache_home_os/bin/apachectl.in" ; then
216 make apache-for-dist
217 fi
218
219 replace_list="conf/extra/httpd-dav.conf \
220 conf/extra/httpd-manual.conf \
221 conf/extra/httpd-autoindex.conf \
222 conf/extra/httpd-vhosts.conf \
223 conf/extra/httpd-ssl.conf \
224 conf/extra/httpd-multilang-errordoc.conf \
225 conf/original/extra/httpd-dav.conf \
226 conf/original/extra/httpd-manual.conf \
227 conf/original/extra/httpd-autoindex.conf \
228 conf/original/extra/httpd-vhosts.conf \
229 conf/original/extra/httpd-ssl.conf \
230 conf/original/extra/httpd-multilang-errordoc.conf \
231 conf/original/httpd.conf\
232 lib/apr-util-1/apr_dbd_odbc.la \
233 lib/apr-util-1/apr_dbd_sqlite3.la \
234 lib/pkgconfig/apr-util-1.pc \
235 lib/pkgconfig/apr-1.pc \
236 lib/libaprutil-1.la \
237 lib/libapr-1.la \
238 build/config_vars.mk \
239 build/config.nice \
240 build/apr_rules.mk \
241 bin/dbmmanage \
242 bin/apu-1-config \
243 bin/apr-1-config \
244 include/ap_config_auto.h \
245 include/ap_config_layout.h"
246
247 for one_file in apachectl envvars envvars-std ; do
248 /bin/cp "$apache_home_os/bin/$one_file.in" "$apache_home_os/bin/$one_file"
249 done
250
251 for one_file in $replace_list ; do
252 /bin/cp "$apache_home_os/$one_file.in" "$apache_home_os/$one_file"
253 done
254
255 /bin/cp "$apache_home_os/bin/apr-1-config.in" "$apache_home_os/bin/apr-1-config"
256
257 /bin/cp "$apache_home_os/bin/apu-1-config.in" "$apache_home_os/bin/apu-1-config"
258
259 /bin/cp "$apache_home_os/build/config_vars.mk.in" "$apache_home_os/build/config_vars.mk"
260
261# replace template files with active versions. The following will generate a httpd.conf
262# file with placeholder strings, all of which we'll replace shortly hereafter.
263 bash "$apache_home_os/install-bindist.sh" "$apache_home_os"
264
265 log4jprop=$GSDLHOME/lib/java/log4j.properties
266 sed "s^@gsdl2home@^$GSDLHOME^g" "$log4jprop.in" > "$log4jprop"
267
268 for one_file in gs2-server.app gli.app client-gli.app gems.app ; do
269 if test -e "$one_file/Contents/document.wflow" ; then
270 rm -f "$one_file/Contents/document.wflow"
271 fi
272 done
273
274 configure-web $1
275 fi
276}
277
278function web-status {
279 test-gsdlhome
280 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl status
281}
282
283function web-start {
284 test-gsdlhome
285 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl start
286 if [ $? = 0 ] ; then
287 echo $MONITOR_SUCCESS;
288 else
289 echo $MONITOR_FAILED;
290 fi
291 echo $MONITOR_FINISHED;
292}
293
294function web-restart {
295 test-gsdlhome
296 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl restart
297 if [ $? = 0 ] ; then
298 echo $MONITOR_SUCCESS;
299 else
300 echo $MONITOR_FAILED;
301 fi
302 echo $MONITOR_FINISHED;
303}
304
305function web-graceful {
306 test-gsdlhome
307 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl graceful
308 if [ $? = 0 ] ; then
309 echo $MONITOR_SUCCESS;
310 else
311 echo $MONITOR_FAILED;
312 fi
313 echo $MONITOR_FINISHED;
314}
315
316function web-stop-tested {
317# This version runs without testing for GSDLHOME
318# Useful to be run as a target when we know test-gsdlhome has already
319# been done. This avoids an unnecessary repetition of printing
320# out the values of GSDLHOME and GSDLOS
321 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
322 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl stop ;
323 fi
324}
325
326function web-stop {
327 test-gsdlhome
328 web-stop-tested
329 if [ $? = 0 ] ; then
330 echo $MONITOR_SUCCESS;
331 else
332 echo $MONITOR_FAILED;
333 fi
334 echo $MONITOR_FINISHED;
335}
336
337function usage {
338 echo ""
339 echo " Usage: $0 <command>"
340 echo " where <command> is any of the following: "
341 echo " web-start"
342 echo " web-stop"
343 echo " web-restart"
344 echo " web-status"
345 echo " web-graceful"
346 echo " configure-admin"
347 echo " configure-web [config-filename]"
348 echo " configure-apache [config-filename]"
349 echo " configure-cgi"
350 echo " reset-gsdlhome [config-filename]"
351 echo " (Save a copy of $cgibin/gsdlsite.cfg to preserve any customisations)"
352 echo " test-gsdlhome"
353 echo " web-stop-tested"
354 echo ""
355}
356
357
358if [[ $# < 1 || $# > 2 ]] ; then
359 usage
360 exit 0
361fi
362
363target=$1
364configfile=$2
365
366# remove any extraneous double quotes
367configfile=${configfile//\"/}
368
369# if there's a libiconv.dylib in gnome-lib-mimimal's lib folder, then apache-httpd would have been compiled dependent on it
370# in such a case, need to add it to the (DY)LD_LIBRARY_PATH. This happens with Mac Lion, may happen with andropid.
371if [ -f $GSDLHOME/ext/gnome-lib-minimal/$GSDLOS/lib/libiconv.dylib ] || [ -f $GSDLHOME/ext/gnome-lib/$GSDLOS/lib/libiconv.dylib ] ; then
372 if [ $GSDLOS = "darwin" ] ; then
373 DYLD_LIBRARY_PATH=$GSDLHOME/ext/gnome-lib-minimal/$GSDLOS/lib:$DYLD_LIBRARY_PATH
374 # DYLD_FALLBACK_LIB_PATH doesn't work with apache-httpd:
375 #DYLD_FALLBACK_LIBRARY_PATH=$GSDLHOME/ext/gnome-lib-minimal/$GSDLOS/lib:$DYLD_FALLBACK_LIBRARY_PATH
376 elif [ $GSDLOS = "linux" ] ; then
377 LD_LIBRARY_PATH=$GSDLHOME/ext/gnome-lib-minimal/$GSDLOS/lib:$LD_LIBRARY_PATH
378 fi
379fi
380
381case $target in
382 web-start)
383 web-start;;
384 web-stop)
385 web-stop;;
386 web-restart)
387 web-restart;;
388 web-status)
389 web-status;;
390 web-graceful)
391 web-graceful;;
392 configure-admin)
393 configure-admin;;
394 configure-web)
395 configure-web $configfile;;
396 configure-apache)
397 configure-apache $configfile;;
398 configure-cgi)
399 configure-cgi;;
400 set-port)
401 configure-port-and-connection;;
402 reset-gsdlhome)
403 reset-gsdlhome;;
404 test-gsdlhome)
405 test-gsdlhome;;
406 web-stop-tested)
407 web-stop-tested;;
408 *)
409 echo
410 echo "Command unrecognised: $target"
411 usage;;
412
413esac
414
415# jump back to directory we originally got called from
416cd "$storedir"
417exit;
Note: See TracBrowser for help on using the repository browser.