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

Last change on this file since 23966 was 23966, checked in by ak19, 13 years ago

More changes to do with reset-gsdlhome.

  • Property svn:executable set to *
File size: 7.9 KB
RevLine 
[18851]1#!/bin/bash
2
[19250]3testdone=0
4
[23948]5cgibin="cgi-bin"
6if [ -d "cgi-bin/$GSDLOS$GSDLARCH" ] ; then
7 cgibin="cgi-bin/$GSDLOS$GSDLARCH"
8fi
9
10
[18851]11function test-gsdlhome {
[19250]12 if [ $testdone == "0" ] ; then
13 if test -z "$GSDLHOME" ; then
14 echo "" ;
15 echo "Environment variable GSDLHOME not set." ;
16 echo " This needs to be set to run this gsicontrol command." ;
17 echo " Have you run 'source setup.bash'?" ;
18 echo "" ;
19 exit 1
20 else
21 echo "Using: " ;
22 echo " GSDLHOME = $GSDLHOME" ;
23 echo " GSDLOS = $GSDLOS" ;
24 fi
25 testdone=1
[18851]26 fi
[19250]27}
[18851]28
29function configure-cgi {
30 test-gsdlhome
[23948]31 if test ! -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
32 echo "Configuring $cgibin/gsdlsite.cfg" ;
33 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "$cgibin/gsdlsite.cfg.in" > "$cgibin/gsdlsite.cfg" ;
[18851]34 else
35 echo "WARNING: Nothing done for make configure-cgi." ;
36 echo " If you wish to regenerate the file " ;
[23948]37 echo " $GSDLHOME/$cgibin/gsdlsite.cfg" ;
[18851]38 echo " from scratch, delete the existing file first." ;
39 fi
40}
41
42function configure-admin {
43 test-gsdlhome
44 echo "" ;
45 echo "Configuring admin user password:" ;
46 encrypted_password=`getpw` ;
47 if [ $? = "0" ] ; then
48 echo -e "[admin]\n<enabled>true\n<groups>administrator,colbuilder,all-collections-editor\n<password>$encrypted_password\n<username>admin" \
[19140]49 | txt2db -append "$GSDLHOME/etc/users.gdb" ;
[18851]50 else
51 echo "Did not set password" ;
52 fi
53 echo ""
54}
55
[19250]56
[20619]57function configure-port-and-connection {
[18851]58 test-gsdlhome
[20619]59
[18851]60 echo "Enter port number to use:"
61 read port ;
[20622]62 echo "Enter host IP to allow (127.0.0.1 is included by default):"
63 read hostIP ;
[23252]64 echo "Enter hostname or list of hosts to allow (localhost included by default):"
65 read hosts ;
[19250]66 echo "Allow external connections [yes/no]:"
[20619]67 read connection ;
[23134]68 if [ "x$connection" = "xyes" ] || [ "x$connection" = "xy" ] ; then
[20619]69 allowfromall="Allow"
70 else
[23252]71 allowfromall="Deny"
[19250]72 fi
73
[20829]74 lib_path_var="LD_LIBRARY_PATH" ;
[20838]75 if [ $GSDLOS = "darwin" ] ; then
[20829]76 lib_path_var="DYLD_LIBRARY_PATH"
77 fi
78
[23948]79 if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
80 collecthome=`egrep "^collecthome" "$GSDLHOME/$cgibin/gsdlsite.cfg" | awk '{print $2}'` ;
[22635]81 fi
82 if test -z $collecthome ; then
83 collecthome="$GSDLHOME/collect" ;
84 fi
85
[18851]86 if test ! -z $port ; then
87 echo "Port: $port" ;
88 echo "Stopping web server (if running)" ;
89 web-stop-tested ;
90 echo "Setting config file to use port $port";
[23948]91 cat "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf.in" \
[18851]92 | sed "s@\*\*PORT\*\*@$port@g" \
[20619]93 | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
[20622]94 | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
[23252]95 | sed "s@\*\*HOSTS\*\*@$hosts@g" \
[22635]96 | sed "s@\*\*COLLECTHOME\*\*@$collecthome@g" \
[18851]97 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
[23948]98 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH@g" \
[20829]99 | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
[23948]100 > "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ;
[18851]101 echo "Type '$0 web-start' to start the web server running on port $port" ;
102 fi ;
103 echo "Done" ;
104}
105
106
107MONITOR_SUCCESS="MAKE SUCCESSFUL"
108MONITOR_FAILED="MAKE FAILED"
109MONITOR_FINISHED="MAKE DONE"
110
111function configure-apache {
112 test-gsdlhome
[18866]113 configfile=$1 ;
[19023]114# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
[18866]115 if [ "x$configfile" = "x" ]; then
[19023]116 if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
117 cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
118 fi
[18866]119 configfile="$GSDLHOME/llssite.cfg";
120 fi ;
[18851]121 echo "Configuring the apache webserver..." ;
[18866]122 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
[20622]123 hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
[23252]124 hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;
[20603]125
[19250]126 externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
[23134]127 if [ "x$externalaccess" = "x1" ] ; then
[19250]128 externalaccess="yes"
129 else
130 externalaccess="no"
131 fi
132
[23252]133 echo -e "$port\n$hostIP\n$hosts\n$externalaccess" | configure-port-and-connection ;
[23948]134 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
[18851]135 echo $MONITOR_SUCCESS;
136 else
137 echo $MONITOR_FAILED;
138 fi
139 echo $MONITOR_FINISHED
140}
141
142function configure-web {
143 configure-cgi
[18866]144 configure-apache $1
[18851]145}
146
[23945]147# forces configure-cgi by deleting gsdlsite.cfg
[23966]148function reset-gsdlhome {
149 echo "" ;
[23948]150 if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
[23966]151 /bin/mv "$GSDLHOME/$cgibin/gsdlsite.cfg" "$GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
152 echo "**** Regenerating $GSDLHOME/$cgibin/gsdlsite.cfg" ;
153 echo "**** Previous version of file now $GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
[23945]154 fi
[23963]155
[23966]156 log4jprop=$GSDLHOME/lib/java/log4j.properties
157 sed "s^@gsdl2home@^$GSDLHOME^g" "$log4jprop.in" > "$log4jprop"
158
[23963]159 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "gs2-server.app/Contents/document.wflow.in" > "gs2-server.app/Contents/document.wflow"
160 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "gli.app/Contents/document.wflow.in" > "gli.app/Contents/document.wflow"
161 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "client-gli.app/Contents/document.wflow.in" > "client-gli.app/Contents/document.wflow"
162 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "gems.app/Contents/document.wflow.in" > "gems.app/Contents/document.wflow"
163
[23945]164 configure-web $1
165}
166
[18851]167function web-status {
168 test-gsdlhome
[23948]169 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl status
[18851]170}
171
172function web-start {
173 test-gsdlhome
[23948]174 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl start
[20342]175 if [ $? = 0 ] ; then
176 echo $MONITOR_SUCCESS;
177 else
178 echo $MONITOR_FAILED;
179 fi
180 echo $MONITOR_FINISHED;
[18851]181}
182
183function web-restart {
184 test-gsdlhome
[23948]185 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl restart
[20342]186 if [ $? = 0 ] ; then
187 echo $MONITOR_SUCCESS;
188 else
189 echo $MONITOR_FAILED;
190 fi
191 echo $MONITOR_FINISHED;
[18851]192}
193
194function web-graceful {
195 test-gsdlhome
[23948]196 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl graceful
[20342]197 if [ $? = 0 ] ; then
198 echo $MONITOR_SUCCESS;
199 else
200 echo $MONITOR_FAILED;
201 fi
202 echo $MONITOR_FINISHED;
[18851]203}
204
205function web-stop-tested {
206# This version runs without testing for GSDLHOME
207# Useful to be run as a target when we know test-gsdlhome has already
[20637]208# been done. This avoids an unnecessary repetition of printing
[18851]209# out the values of GSDLHOME and GSDLOS
[23948]210 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
211 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl stop ;
[18851]212 fi
213}
214
215function web-stop {
216 test-gsdlhome
217 web-stop-tested
[20342]218 if [ $? = 0 ] ; then
219 echo $MONITOR_SUCCESS;
220 else
221 echo $MONITOR_FAILED;
222 fi
223 echo $MONITOR_FINISHED;
[18851]224}
225
[19453]226function usage {
[18851]227 echo ""
228 echo " Usage: $0 <command>"
229 echo " where <command> is any of the following: "
230 echo " web-start"
231 echo " web-stop"
232 echo " web-restart"
233 echo " web-status"
234 echo " web-graceful"
235 echo " configure-admin"
[18866]236 echo " configure-web [config-filename]"
237 echo " configure-apache [config-filename]"
[18851]238 echo " configure-cgi"
[23948]239 echo " reset-gsdlhome [config-filename]\n\t(Save a copy of $cgibin/gsdlsite.cfg to preserve any customisations)"
[18851]240 echo " test-gsdlhome"
241 echo " web-stop-tested"
242 echo ""
[19453]243}
244
245
246if [[ $# < 1 || $# > 2 ]] ; then
247 usage
[18851]248 exit 0
249fi
250
251target=$1
[18866]252configfile=$2
[18851]253
[20919]254# remove any extraneous double quotes
255configfile=${configfile//\"/}
256
[18851]257case $target in
258 web-start)
259 web-start;;
260 web-stop)
261 web-stop;;
262 web-restart)
263 web-restart;;
264 web-status)
265 web-status;;
266 web-graceful)
267 web-graceful;;
268 configure-admin)
269 configure-admin;;
270 configure-web)
[18866]271 configure-web $configfile;;
[18851]272 configure-apache)
[18866]273 configure-apache $configfile;;
[18851]274 configure-cgi)
275 configure-cgi;;
[20619]276 set-port)
277 configure-port-and-connection;;
[23945]278 reset-gsdlhome)
279 reset-gsdlhome;;
[18851]280 test-gsdlhome)
281 test-gsdlhome;;
282 web-stop-tested)
283 web-stop-tested;;
[19453]284 *)
285 echo
286 echo "Command unrecognised: $target"
287 usage;;
288
[18851]289esac
290
[19257]291exit;
Note: See TracBrowser for help on using the repository browser.