source: gsdl/trunk/gsicontrol.sh@ 20342

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

Changes Dr Bainbridge made to get the apache web server (local library server) to work again on the Mac. 1. It seems that the DYLD_LIBRARY_PATH was pointing to a different apache web server's lib folder and that was out of date. Therefore setup.bash now adds the apache web server's lib folder to the DYLD_LIBRARY_PATH. 2. gsicontrol.sh now checks the return value of starting and stopping the apache web server and only if successful does it now print out MONITOR_SUCCESS. Otherwise it now prints out MONITOR_FAILED.

  • Property svn:executable set to *
File size: 5.6 KB
Line 
1#!/bin/bash
2
3testdone=0
4
5function test-gsdlhome {
6 if [ $testdone == "0" ] ; then
7 if test -z "$GSDLHOME" ; then
8 echo "" ;
9 echo "Environment variable GSDLHOME not set." ;
10 echo " This needs to be set to run this gsicontrol command." ;
11 echo " Have you run 'source setup.bash'?" ;
12 echo "" ;
13 exit 1
14 else
15 echo "Using: " ;
16 echo " GSDLHOME = $GSDLHOME" ;
17 echo " GSDLOS = $GSDLOS" ;
18 fi
19 testdone=1
20 fi
21}
22
23function configure-cgi {
24 test-gsdlhome
25 if test ! -e $GSDLHOME/cgi-bin/gsdlsite.cfg ; then
26 echo "Configuring cgi-bin/gsdlsite.cfg" ;
27 sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" cgi-bin/gsdlsite.cfg.in > cgi-bin/gsdlsite.cfg ;
28 else
29 echo "WARNING: Nothing done for make configure-cgi." ;
30 echo " If you wish to regenerate the file " ;
31 echo " $GSDLHOME/cgi-bin/gsdlsite.cfg" ;
32 echo " from scratch, delete the existing file first." ;
33 fi
34}
35
36function configure-admin {
37 test-gsdlhome
38 echo "" ;
39 echo "Configuring admin user password:" ;
40 encrypted_password=`getpw` ;
41 if [ $? = "0" ] ; then
42 echo -e "[admin]\n<enabled>true\n<groups>administrator,colbuilder,all-collections-editor\n<password>$encrypted_password\n<username>admin" \
43 | txt2db -append "$GSDLHOME/etc/users.gdb" ;
44 else
45 echo "Did not set password" ;
46 fi
47 echo ""
48}
49
50
51function _configure-port-and-connection {
52 test-gsdlhome
53 echo "Enter port number to use:"
54 read port ;
55 echo "Allow external connections [yes/no]:"
56 read connection ;
57 if [ $connection = "yes" ] || [ $connection = "y" ] ; then
58 allowfrom="all"
59 else
60 allowfrom="127.0.0.1"
61 fi
62
63 if test ! -z $port ; then
64 echo "Port: $port" ;
65 echo "Stopping web server (if running)" ;
66 web-stop-tested ;
67 echo "Setting config file to use port $port";
68 cat "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf.in" \
69 | sed "s@\*\*PORT\*\*@$port@g" \
70 | sed "s@\*\*CONNECTION\*\*@$allowfrom@g" \
71 | sed "s@\*\*GSDLHOME\*\*@$GSDLHOME@g" \
72 | sed "s@\*\*APACHE_HOME_OS\*\*@$GSDLHOME/apache-httpd/$GSDLOS@g" \
73 > "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ;
74 echo "Type '$0 web-start' to start the web server running on port $port" ;
75 fi ;
76 echo "Done" ;
77}
78
79
80MONITOR_SUCCESS="MAKE SUCCESSFUL"
81MONITOR_FAILED="MAKE FAILED"
82MONITOR_FINISHED="MAKE DONE"
83
84function configure-apache {
85 test-gsdlhome
86 configfile=$1 ;
87# if no configfile given, launch it with llssite.cfg. Create it from the template if needed.
88 if [ "x$configfile" = "x" ]; then
89 if test ! -e "$GSDLHOME/llssite.cfg" && test -e "$GSDLHOME/llssite.cfg.in" ; then
90 cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg" ;
91 fi
92 configfile="$GSDLHOME/llssite.cfg";
93 fi ;
94 echo "Configuring the apache webserver..." ;
95 port=`egrep "^portnumber" $configfile | awk -F= '{print $2}'` ;
96
97 externalaccess=`egrep "^externalaccess" $configfile | awk -F= '{print $2}'` ;
98 if [ $externalaccess == "1" ] ; then
99 externalaccess="yes"
100 else
101 externalaccess="no"
102 fi
103
104 echo -e "$port\n$externalaccess" | _configure-port-and-connection ;
105 if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
106 echo $MONITOR_SUCCESS;
107 else
108 echo $MONITOR_FAILED;
109 fi
110 echo $MONITOR_FINISHED
111}
112
113function configure-web {
114 configure-cgi
115 configure-apache $1
116}
117
118function web-status {
119 test-gsdlhome
120 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl status
121}
122
123function web-start {
124 test-gsdlhome
125 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl start
126 if [ $? = 0 ] ; then
127 echo $MONITOR_SUCCESS;
128 else
129 echo $MONITOR_FAILED;
130 fi
131 echo $MONITOR_FINISHED;
132}
133
134function web-restart {
135 test-gsdlhome
136 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl restart
137 if [ $? = 0 ] ; then
138 echo $MONITOR_SUCCESS;
139 else
140 echo $MONITOR_FAILED;
141 fi
142 echo $MONITOR_FINISHED;
143}
144
145function web-graceful {
146 test-gsdlhome
147 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl graceful
148 if [ $? = 0 ] ; then
149 echo $MONITOR_SUCCESS;
150 else
151 echo $MONITOR_FAILED;
152 fi
153 echo $MONITOR_FINISHED;
154}
155
156function web-stop-tested {
157# This version runs without testing for GSDLHOME
158# Useful to be run as a target when we know test-gsdlhome has already
159# been done. This avoids a unnecessary repetition of printing
160# out the values of GSDLHOME and GSDLOS
161 if test -e "$GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf" ; then
162 $GSDLHOME/apache-httpd/$GSDLOS/bin/apachectl stop ;
163 fi
164}
165
166function web-stop {
167 test-gsdlhome
168 web-stop-tested
169 if [ $? = 0 ] ; then
170 echo $MONITOR_SUCCESS;
171 else
172 echo $MONITOR_FAILED;
173 fi
174 echo $MONITOR_FINISHED;
175}
176
177function usage {
178 echo ""
179 echo " Usage: $0 <command>"
180 echo " where <command> is any of the following: "
181 echo " web-start"
182 echo " web-stop"
183 echo " web-restart"
184 echo " web-status"
185 echo " web-graceful"
186 echo " configure-admin"
187 echo " configure-web [config-filename]"
188 echo " configure-apache [config-filename]"
189 echo " configure-cgi"
190 echo " test-gsdlhome"
191 echo " web-stop-tested"
192 echo ""
193}
194
195
196if [[ $# < 1 || $# > 2 ]] ; then
197 usage
198 exit 0
199fi
200
201target=$1
202configfile=$2
203
204case $target in
205 web-start)
206 web-start;;
207 web-stop)
208 web-stop;;
209 web-restart)
210 web-restart;;
211 web-status)
212 web-status;;
213 web-graceful)
214 web-graceful;;
215 configure-admin)
216 configure-admin;;
217 configure-web)
218 configure-web $configfile;;
219 configure-apache)
220 configure-apache $configfile;;
221 configure-cgi)
222 configure-cgi;;
223 test-gsdlhome)
224 test-gsdlhome;;
225 web-stop-tested)
226 web-stop-tested;;
227 *)
228 echo
229 echo "Command unrecognised: $target"
230 usage;;
231
232esac
233
234exit;
Note: See TracBrowser for help on using the repository browser.