root/main/trunk/greenstone2/gsicontrol.sh @ 24108

Revision 23988, 10.6 KB (checked in by ak19, 9 years ago)

In gs2-server.sh, no longer redirecting stderr of call call to gsicontrol.sh reset-gsdlhome into the void, only the stdout. This means that the invalid port value found in httpd.conf when web-stop-tested is called by configure-apache (the value is the placeholder string **PORT** at this stage), is handled differently.

  • Property svn:executable set to *
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    cat "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf.in" \
108    | sed "s@\*\*PORT\*\*@$port@g" \
109    | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
110    | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
111    | sed "s@\*\*HOSTS\*\*@$hosts@g" \
112    | sed "s@\*\*COLLECTHOME\*\*@$collecthome@g" \
113    | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
114    | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH@g" \
115    | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
116    > "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ;
117    echo "Type '$0 web-start' to start the web server running on port $port" ;
118    fi ;
119    echo "Done" ;
120}
121
122
123MONITOR_SUCCESS="MAKE SUCCESSFUL"
124MONITOR_FAILED="MAKE FAILED"
125MONITOR_FINISHED="MAKE DONE"
126
127function configure-apache {
128    test-gsdlhome
129    configfile=$1 ;
130# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
131    if [ "x$configfile" = "x" ]; then
132    if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
133        cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
134    fi
135    configfile="$GSDLHOME/llssite.cfg";
136    fi ;
137    echo "Configuring the apache webserver..." ;
138    port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
139    hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
140    hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;   
141   
142    externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
143    if [ "x$externalaccess" = "x1" ] ; then
144    externalaccess="yes"
145    else
146    externalaccess="no"
147    fi
148
149    echo -e "$port\n$hostIP\n$hosts\n$externalaccess" | configure-port-and-connection ;
150    if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
151    echo $MONITOR_SUCCESS;
152    else
153    echo $MONITOR_FAILED;
154    fi
155    echo $MONITOR_FINISHED
156}
157
158function configure-web {
159    for one_file in gs2-server.app gli.app client-gli.app gems.app ; do     
160    if test ! -e "$one_file/Contents/document.wflow" ; then
161        sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "$one_file/Contents/document.wflow.in" > "$one_file/Contents/document.wflow"
162    fi
163    done ;
164
165    configure-cgi
166    configure-apache $1
167}
168
169# forces configure-cgi by deleting gsdlsite.cfg
170function reset-gsdlhome {
171    echo "" ;
172    if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
173    /bin/mv "$GSDLHOME/$cgibin/gsdlsite.cfg" "$GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
174    echo "**** Regenerating $GSDLHOME/$cgibin/gsdlsite.cfg" ;
175    echo "**** Previous version of file now $GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
176    fi
177
178    apache_home_os="$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH"
179
180    if test ! -e "$apache_home_os/bin/apachectl.in" ; then
181    make apache-for-dist
182    fi
183   
184    replace_list="conf/extra/httpd-dav.conf \
185            conf/extra/httpd-manual.conf \
186            conf/extra/httpd-autoindex.conf \
187            conf/extra/httpd-vhosts.conf \
188            conf/extra/httpd-ssl.conf \
189            conf/extra/httpd-multilang-errordoc.conf \
190            conf/original/extra/httpd-dav.conf \
191            conf/original/extra/httpd-manual.conf \
192            conf/original/extra/httpd-autoindex.conf \
193            conf/original/extra/httpd-vhosts.conf \
194            conf/original/extra/httpd-ssl.conf \
195            conf/original/extra/httpd-multilang-errordoc.conf \
196            conf/original/httpd.conf\
197            lib/apr-util-1/apr_dbd_odbc.la \
198            lib/apr-util-1/apr_dbd_sqlite3.la \
199            lib/pkgconfig/apr-util-1.pc \
200            lib/pkgconfig/apr-1.pc \
201            lib/libaprutil-1.la \
202            lib/libapr-1.la \
203            build/config_vars.mk \
204            build/config.nice \
205            build/apr_rules.mk \
206            bin/dbmmanage \
207            bin/apu-1-config \
208            bin/apr-1-config \
209            include/ap_config_auto.h \
210            include/ap_config_layout.h"
211
212    for one_file in apachectl envvars envvars-std ; do
213    /bin/cp "$apache_home_os/bin/$one_file.in" "$apache_home_os/bin/$one_file"
214    done
215   
216    for one_file in $replace_list ; do
217    /bin/cp "$apache_home_os/$one_file.in" "$apache_home_os/$one_file"
218    done
219   
220    /bin/cp "$apache_home_os/bin/apr-1-config.in" "$apache_home_os/bin/apr-1-config"
221   
222    /bin/cp "$apache_home_os/bin/apu-1-config.in" "$apache_home_os/bin/apu-1-config"
223   
224    /bin/cp "$apache_home_os/build/config_vars.mk.in" "$apache_home_os/build/config_vars.mk"
225
226# replace template files with active versions. The following will generate a httpd.conf
227# file with placeholder strings, all of which we'll replace shortly hereafter.
228    bash "$apache_home_os/install-bindist.sh" "$apache_home_os"
229   
230    log4jprop=$GSDLHOME/lib/java/log4j.properties
231    sed "s^@gsdl2home@^$GSDLHOME^g" "$log4jprop.in" > "$log4jprop"
232
233    for one_file in gs2-server.app gli.app client-gli.app gems.app ; do
234    if test -e "$one_file/Contents/document.wflow" ; then
235        rm -f "$one_file/Contents/document.wflow"
236    fi
237    done
238
239    configure-web $1
240}
241
242function web-status {
243    test-gsdlhome
244    $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl status
245}
246
247function web-start {
248    test-gsdlhome
249    $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl start
250    if [ $? = 0 ] ; then
251    echo $MONITOR_SUCCESS;
252    else
253    echo $MONITOR_FAILED;
254    fi
255    echo $MONITOR_FINISHED;
256}
257
258function web-restart {
259    test-gsdlhome
260    $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl restart
261    if [ $? = 0 ] ; then
262    echo $MONITOR_SUCCESS;
263    else
264    echo $MONITOR_FAILED;
265    fi
266    echo $MONITOR_FINISHED;
267}
268
269function web-graceful {
270    test-gsdlhome
271    $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl graceful
272    if [ $? = 0 ] ; then
273    echo $MONITOR_SUCCESS;
274    else
275    echo $MONITOR_FAILED;
276    fi
277    echo $MONITOR_FINISHED;
278}
279
280function web-stop-tested {
281# This version runs without testing for GSDLHOME
282# Useful to be run as a target when we know test-gsdlhome has already
283# been done.  This avoids an unnecessary repetition of printing
284# out the values of GSDLHOME and GSDLOS
285    if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
286    $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl stop ;
287    fi
288}
289
290function web-stop {
291    test-gsdlhome
292    web-stop-tested
293    if [ $? = 0 ] ; then
294    echo $MONITOR_SUCCESS;
295    else
296    echo $MONITOR_FAILED;
297    fi
298    echo $MONITOR_FINISHED;
299}
300
301function usage {
302    echo ""
303    echo "   Usage: $0 <command>"
304    echo "          where <command> is any of the following: "
305    echo "   web-start"
306    echo "   web-stop"
307    echo "   web-restart"
308    echo "   web-status"
309    echo "   web-graceful"
310    echo "   configure-admin"
311    echo "   configure-web [config-filename]"
312    echo "   configure-apache [config-filename]"
313    echo "   configure-cgi"
314    echo "   reset-gsdlhome [config-filename]\n\t(Save a copy of $cgibin/gsdlsite.cfg to preserve any customisations)"
315    echo "   test-gsdlhome"
316    echo "   web-stop-tested"
317    echo ""
318}
319
320
321if [[ $# < 1  || $# > 2 ]] ; then
322    usage
323    exit 0
324fi
325
326target=$1
327configfile=$2
328
329# remove any extraneous double quotes
330configfile=${configfile//\"/}
331
332case $target in
333    web-start)
334    web-start;;
335    web-stop)
336    web-stop;;
337    web-restart)
338    web-restart;;
339    web-status)
340    web-status;;
341    web-graceful)
342    web-graceful;;
343    configure-admin)
344    configure-admin;;
345    configure-web)
346    configure-web $configfile;;
347    configure-apache)
348    configure-apache $configfile;;
349    configure-cgi)
350    configure-cgi;;
351    set-port)
352    configure-port-and-connection;;
353    reset-gsdlhome)
354    reset-gsdlhome;;
355    test-gsdlhome)
356    test-gsdlhome;;
357    web-stop-tested)
358    web-stop-tested;;
359    *)
360    echo
361        echo "Command unrecognised: $target"
362    usage;;
363
364esac
365
366# jump back to directory we originally got called from
367cd "$storedir"
368exit;
Note: See TracBrowser for help on using the browser.