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

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

Adjustments to configure-web and reset-gsdlhome. Note that at present, if using an SVN version of GS2, then before you tell GS2 that you've changed its installation location, you need to first run make apache-for-dist in the top level folder. This will allow you to run the RESET-GREENSTONE.sh script in GS svn's other-projects. That script will adjust the apache config files before running gsicontrol.sh's reset-gsdlhome target.

  • Property svn:executable set to *
File size: 8.3 KB
Line 
1#!/bin/bash
2
3testdone=0
4
5cgibin="cgi-bin"
6if [ -d "cgi-bin/$GSDLOS$GSDLARCH" ] ; then
7 cgibin="cgi-bin/$GSDLOS$GSDLARCH"
8fi
9
10
11function test-gsdlhome {
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
26 fi
27}
28
29function configure-cgi {
30 test-gsdlhome
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" ;
34 else
35 echo "WARNING: Nothing done for make configure-cgi." ;
36 echo " If you wish to regenerate the file " ;
37 echo " $GSDLHOME/$cgibin/gsdlsite.cfg" ;
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" \
49 | txt2db -append "$GSDLHOME/etc/users.gdb" ;
50 else
51 echo "Did not set password" ;
52 fi
53 echo ""
54}
55
56
57function configure-port-and-connection {
58 test-gsdlhome
59
60 echo "Enter port number to use:"
61 read port ;
62 echo "Enter host IP to allow (127.0.0.1 is included by default):"
63 read hostIP ;
64 echo "Enter hostname or list of hosts to allow (localhost included by default):"
65 read hosts ;
66 echo "Allow external connections [yes/no]:"
67 read connection ;
68 if [ "x$connection" = "xyes" ] || [ "x$connection" = "xy" ] ; then
69 allowfromall="Allow"
70 else
71 allowfromall="Deny"
72 fi
73
74 lib_path_var="LD_LIBRARY_PATH" ;
75 if [ $GSDLOS = "darwin" ] ; then
76 lib_path_var="DYLD_LIBRARY_PATH"
77 fi
78
79 if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
80 collecthome=`egrep "^collecthome" "$GSDLHOME/$cgibin/gsdlsite.cfg" | awk '{print $2}'` ;
81 fi
82 if test -z $collecthome ; then
83 collecthome="$GSDLHOME/collect" ;
84 fi
85
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";
91 cat "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf.in" \
92 | sed "s@\*\*PORT\*\*@$port@g" \
93 | sed "s@\*\*CONNECTPERMISSION\*\*@$allowfromall@g" \
94 | sed "s@\*\*HOST_IP\*\*@$hostIP@g" \
95 | sed "s@\*\*HOSTS\*\*@$hosts@g" \
96 | sed "s@\*\*COLLECTHOME\*\*@$collecthome@g" \
97 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
98 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH@g" \
99 | sed "s@\*\*LIBRARY_PATH_VAR\*\*@$lib_path_var@g" \
100 > "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ;
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
113 configfile=$1 ;
114# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
115 if [ "x$configfile" = "x" ]; then
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
119 configfile="$GSDLHOME/llssite.cfg";
120 fi ;
121 echo "Configuring the apache webserver..." ;
122 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
123 hostIP=`egrep "^hostIP" $configfile | awk -F= '{print $2}'` ;
124 hosts=`egrep "^hosts" $configfile | awk -F= '{print $2}'` ;
125
126 externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
127 if [ "x$externalaccess" = "x1" ] ; then
128 externalaccess="yes"
129 else
130 externalaccess="no"
131 fi
132
133 echo -e "$port\n$hostIP\n$hosts\n$externalaccess" | configure-port-and-connection ;
134 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
135 echo $MONITOR_SUCCESS;
136 else
137 echo $MONITOR_FAILED;
138 fi
139 echo $MONITOR_FINISHED
140}
141
142function configure-web {
143 if test ! -e "gs2-server.app/Contents/document.wflow" ; then
144 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "gs2-server.app/Contents/document.wflow.in" > "gs2-server.app/Contents/document.wflow"
145 fi
146 if test ! -e "gli.app/Contents/document.wflow" ; then
147 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "gli.app/Contents/document.wflow.in" > "gli.app/Contents/document.wflow"
148 fi
149 if test ! -e "client-gli.app/Contents/document.wflow" ; then
150 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "client-gli.app/Contents/document.wflow.in" > "client-gli.app/Contents/document.wflow"
151 fi
152 if test ! -e "gems.app/Contents/document.wflow" ; then
153 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" "gems.app/Contents/document.wflow.in" > "gems.app/Contents/document.wflow"
154 fi
155
156 configure-cgi
157 configure-apache $1
158}
159
160# forces configure-cgi by deleting gsdlsite.cfg
161function reset-gsdlhome {
162 echo "" ;
163 if test -e "$GSDLHOME/$cgibin/gsdlsite.cfg" ; then
164 /bin/mv "$GSDLHOME/$cgibin/gsdlsite.cfg" "$GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
165 echo "**** Regenerating $GSDLHOME/$cgibin/gsdlsite.cfg" ;
166 echo "**** Previous version of file now $GSDLHOME/$cgibin/gsdlsite.cfg.bak" ;
167 fi
168
169 log4jprop=$GSDLHOME/lib/java/log4j.properties
170 sed "s^@gsdl2home@^$GSDLHOME^g" "$log4jprop.in" > "$log4jprop"
171
172 rm -f "gs2-server.app/Contents/document.wflow"
173 rm -f "gli.app/Contents/document.wflow"
174 rm -f "client-gli.app/Contents/document.wflow"
175 rm -f "gems.app/Contents/document.wflow"
176
177 configure-web $1
178}
179
180function web-status {
181 test-gsdlhome
182 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl status
183}
184
185function web-start {
186 test-gsdlhome
187 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl start
188 if [ $? = 0 ] ; then
189 echo $MONITOR_SUCCESS;
190 else
191 echo $MONITOR_FAILED;
192 fi
193 echo $MONITOR_FINISHED;
194}
195
196function web-restart {
197 test-gsdlhome
198 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl restart
199 if [ $? = 0 ] ; then
200 echo $MONITOR_SUCCESS;
201 else
202 echo $MONITOR_FAILED;
203 fi
204 echo $MONITOR_FINISHED;
205}
206
207function web-graceful {
208 test-gsdlhome
209 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl graceful
210 if [ $? = 0 ] ; then
211 echo $MONITOR_SUCCESS;
212 else
213 echo $MONITOR_FAILED;
214 fi
215 echo $MONITOR_FINISHED;
216}
217
218function web-stop-tested {
219# This version runs without testing for GSDLHOME
220# Useful to be run as a target when we know test-gsdlhome has already
221# been done. This avoids an unnecessary repetition of printing
222# out the values of GSDLHOME and GSDLOS
223 if test -e "$GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/conf/httpd.conf" ; then
224 $GSDLHOME/apache-httpd/$GSDLOS$GSDLARCH/bin/apachectl stop ;
225 fi
226}
227
228function web-stop {
229 test-gsdlhome
230 web-stop-tested
231 if [ $? = 0 ] ; then
232 echo $MONITOR_SUCCESS;
233 else
234 echo $MONITOR_FAILED;
235 fi
236 echo $MONITOR_FINISHED;
237}
238
239function usage {
240 echo ""
241 echo " Usage: $0 <command>"
242 echo " where <command> is any of the following: "
243 echo " web-start"
244 echo " web-stop"
245 echo " web-restart"
246 echo " web-status"
247 echo " web-graceful"
248 echo " configure-admin"
249 echo " configure-web [config-filename]"
250 echo " configure-apache [config-filename]"
251 echo " configure-cgi"
252 echo " reset-gsdlhome [config-filename]\n\t(Save a copy of $cgibin/gsdlsite.cfg to preserve any customisations)"
253 echo " test-gsdlhome"
254 echo " web-stop-tested"
255 echo ""
256}
257
258
259if [[ $# < 1 || $# > 2 ]] ; then
260 usage
261 exit 0
262fi
263
264target=$1
265configfile=$2
266
267# remove any extraneous double quotes
268configfile=${configfile//\"/}
269
270case $target in
271 web-start)
272 web-start;;
273 web-stop)
274 web-stop;;
275 web-restart)
276 web-restart;;
277 web-status)
278 web-status;;
279 web-graceful)
280 web-graceful;;
281 configure-admin)
282 configure-admin;;
283 configure-web)
284 configure-web $configfile;;
285 configure-apache)
286 configure-apache $configfile;;
287 configure-cgi)
288 configure-cgi;;
289 set-port)
290 configure-port-and-connection;;
291 reset-gsdlhome)
292 reset-gsdlhome;;
293 test-gsdlhome)
294 test-gsdlhome;;
295 web-stop-tested)
296 web-stop-tested;;
297 *)
298 echo
299 echo "Command unrecognised: $target"
300 usage;;
301
302esac
303
304exit;
Note: See TracBrowser for help on using the repository browser.