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

Last change on this file since 31861 was 28576, checked in by ak19, 10 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
RevLine 
[18851]1#!/bin/bash
2
[23982]3storedir="`pwd`"
4thisdir="`dirname \"$0\"`"
5thisdir="`cd \"$thisdir\" && pwd`"
6cd "$thisdir"
7source setup.bash
8
[19250]9testdone=0
10
[23948]11cgibin="cgi-bin"
12if [ -d "cgi-bin/$GSDLOS$GSDLARCH" ] ; then
13 cgibin="cgi-bin/$GSDLOS$GSDLARCH"
14fi
15
16
[18851]17function test-gsdlhome {
[19250]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
[18851]32 fi
[19250]33}
[18851]34
35function configure-cgi {
36 test-gsdlhome
[23948]37 if test ! -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
38 echo "Configuring $cgibin/gsdlsite.cfg" ;
[23982]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" ;
[23988]41 echo "" >> "$cgibin/gsdlsite.cfg" ;
[23982]42 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "$cgibin/gsdlsite.cfg.in" >> "$cgibin/gsdlsite.cfg" ;
[18851]43 else
44 echo "WARNING: Nothing done for make configure-cgi." ;
45 echo " If you wish to regenerate the file " ;
[23948]46 echo " $GSDLHOME/$cgibin/gsdlsite.cfg" ;
[18851]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" \
[19140]58 | txt2db -append "$GSDLHOME/etc/users.gdb" ;
[18851]59 else
60 echo "Did not set password" ;
61 fi
62 echo ""
63}
64
[19250]65
[20619]66function configure-port-and-connection {
[18851]67 test-gsdlhome
[20619]68
[18851]69 echo "Enter port number to use:"
70 read port ;
[20622]71 echo "Enter host IP to allow (127.0.0.1 is included by default):"
72 read hostIP ;
[23252]73 echo "Enter hostname or list of hosts to allow (localhost included by default):"
74 read hosts ;
[19250]75 echo "Allow external connections [yes/no]:"
[20619]76 read connection ;
[23134]77 if [ "x$connection" = "xyes" ] || [ "x$connection" = "xy" ] ; then
[20619]78 allowfromall="Allow"
79 else
[23252]80 allowfromall="Deny"
[19250]81 fi
82
[20829]83 lib_path_var="LD_LIBRARY_PATH" ;
[20838]84 if [ $GSDLOS = "darwin" ] ; then
[20829]85 lib_path_var="DYLD_LIBRARY_PATH"
86 fi
87
[23948]88 if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
89 collecthome=`egrep "^collecthome" "$GSDLHOME/$cgibin/gsdlsite.cfg" | awk '{print $2}'` ;
[22635]90 fi
91 if test -z $collecthome ; then
92 collecthome="$GSDLHOME/collect" ;
93 fi
94
[18851]95 if test ! -z $port ; then
96 echo "Port: $port" ;
[23988]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
[18851]106 echo "Setting config file to use port $port";
[24953]107# Need to remove extra quotes around $collecthome. ${string//abc/xyz} does a replace all on abc with xyz
[23948]108 cat "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf.in" \
[24901]109 | sed "s@\*\*GSDL_OS_ARCH\*\*@$GSDLOS$GSDLARCH@g" \
[18851]110 | sed "s@\*\*PORT\*\*@$port@g" \
[20619]111 | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
[20622]112 | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
[23252]113 | sed "s@\*\*HOSTS\*\*@$hosts@g" \
[24953]114 | sed "s@\*\*COLLECTHOME\*\*@${collecthome//\"/}@g" \
[18851]115 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
[23948]116 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH@g" \
[20829]117 | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
[23948]118 > "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ;
[18851]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
[18866]131 configfile=$1 ;
[19023]132# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
[18866]133 if [ "x$configfile" = "x" ]; then
[19023]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
[18866]137 configfile="$GSDLHOME/llssite.cfg";
138 fi ;
[18851]139 echo "Configuring the apache webserver..." ;
[18866]140 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
[20622]141 hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
[23252]142 hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;
[20603]143
[19250]144 externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
[23134]145 if [ "x$externalaccess" = "x1" ] ; then
[19250]146 externalaccess="yes"
147 else
148 externalaccess="no"
149 fi
150
[23252]151 echo -e "$port\n$hostIP\n$hosts\n$externalaccess" | configure-port-and-connection ;
[23948]152 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
[18851]153 echo $MONITOR_SUCCESS;
154 else
155 echo $MONITOR_FAILED;
156 fi
157 echo $MONITOR_FINISHED
158}
159
160function configure-web {
[23975]161 for one_file in gs2-server.app gli.app client-gli.app gems.app ; do
[24760]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
[23975]166 fi
167 done ;
[23973]168
[18851]169 configure-cgi
[18866]170 configure-apache $1
[18851]171}
172
[24297]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
[23966]177function reset-gsdlhome {
[23973]178 echo "" ;
[24297]179 relocate=yes ;
[24787]180
[27521]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
[24787]182# if this is a perl included with the Greenstone distribution
[23948]183 if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
[24297]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" ;
[24787]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" ;
[27521]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" ;
[24787]205 fi
206
[24297]207 else
208 relocate=
209 fi
210 fi
[23973]211
[24297]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 \
[23982]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
[24297]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
[23988]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.
[24297]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
[23945]276}
277
[18851]278function web-status {
279 test-gsdlhome
[23948]280 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl status
[18851]281}
282
283function web-start {
284 test-gsdlhome
[23948]285 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl start
[20342]286 if [ $? = 0 ] ; then
287 echo $MONITOR_SUCCESS;
288 else
289 echo $MONITOR_FAILED;
290 fi
291 echo $MONITOR_FINISHED;
[18851]292}
293
294function web-restart {
295 test-gsdlhome
[23948]296 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl restart
[20342]297 if [ $? = 0 ] ; then
298 echo $MONITOR_SUCCESS;
299 else
300 echo $MONITOR_FAILED;
301 fi
302 echo $MONITOR_FINISHED;
[18851]303}
304
305function web-graceful {
306 test-gsdlhome
[23948]307 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl graceful
[20342]308 if [ $? = 0 ] ; then
309 echo $MONITOR_SUCCESS;
310 else
311 echo $MONITOR_FAILED;
312 fi
313 echo $MONITOR_FINISHED;
[18851]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
[20637]319# been done. This avoids an unnecessary repetition of printing
[18851]320# out the values of GSDLHOME and GSDLOS
[23948]321 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
322 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl stop ;
[18851]323 fi
324}
325
326function web-stop {
327 test-gsdlhome
328 web-stop-tested
[20342]329 if [ $? = 0 ] ; then
330 echo $MONITOR_SUCCESS;
331 else
332 echo $MONITOR_FAILED;
333 fi
334 echo $MONITOR_FINISHED;
[18851]335}
336
[19453]337function usage {
[18851]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"
[18866]347 echo " configure-web [config-filename]"
348 echo " configure-apache [config-filename]"
[18851]349 echo " configure-cgi"
[24392]350 echo " reset-gsdlhome [config-filename]"
351 echo " (Save a copy of $cgibin/gsdlsite.cfg to preserve any customisations)"
[18851]352 echo " test-gsdlhome"
353 echo " web-stop-tested"
354 echo ""
[19453]355}
356
357
358if [[ $# < 1 || $# > 2 ]] ; then
359 usage
[18851]360 exit 0
361fi
362
363target=$1
[18866]364configfile=$2
[18851]365
[20919]366# remove any extraneous double quotes
367configfile=${configfile//\"/}
368
[28576]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
[18851]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)
[18866]395 configure-web $configfile;;
[18851]396 configure-apache)
[18866]397 configure-apache $configfile;;
[18851]398 configure-cgi)
399 configure-cgi;;
[20619]400 set-port)
401 configure-port-and-connection;;
[23945]402 reset-gsdlhome)
403 reset-gsdlhome;;
[18851]404 test-gsdlhome)
405 test-gsdlhome;;
406 web-stop-tested)
407 web-stop-tested;;
[19453]408 *)
409 echo
410 echo "Command unrecognised: $target"
411 usage;;
412
[18851]413esac
414
[23982]415# jump back to directory we originally got called from
416cd "$storedir"
[19257]417exit;
Note: See TracBrowser for help on using the repository browser.