source: main/trunk/greenstone2/gs2-server.sh@ 23660

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

Sherlock Sam solved the mysterious problem of why the Mac binary's gs2-server.sh was working but not when the apache server was launched through GLI and whey both worked for the source distribution. The reason was that GLI runs gs2-server from the GLI folder, so a mere test for the existence of an apache-httpd dir will fail when done from the GLI fplder, unless prefixed with the full path to it.

  • Property svn:executable set to *
File size: 5.6 KB
Line 
1#!/bin/bash
2
3if [ -z "$serverlang" ]; then
4 serverlang=en
5fi
6
7java_min_version=1.5.0_00
8PROGNAME="gs2-server"
9PROGFULLNAME="Greenstone-Server"
10if [ -z "$PROGABBR" ]; then
11 PROGABBR="GSI"
12fi
13
14function autoset_gsdl_home() {
15
16 # remove leading ./ if present
17 prog="${0#./}"
18
19 isrelative="${prog%%/*}"
20
21 if [ ! -z "$isrelative" ] ; then
22 # some text is left after stripping
23 # => is relative
24 prog="$PWD/$prog"
25 fi
26
27 fulldir="${prog%/*}"
28
29 # remove trailing /. if present
30 eval "$1=\"${fulldir%/.}\""
31}
32
33function isinpath() {
34 for file in `echo $1 | sed 's/:/ /g'`; do
35 if [ "$file" == "$2" ]; then
36 echo true
37 return
38 fi
39 done
40 echo false
41}
42
43
44echo "Greenstone 2 Server"
45echo "Copyright (C) 2009, New Zealand Digital Library Project, University Of Waikato"
46echo "This software comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.txt"
47echo "This is free software, and you are welcome to redistribute it"
48
49## -------- Run the Greenstone 2 Server --------
50
51## ---- Determine GSDLHOME ----
52gsdl2path=
53
54# Some users may set the above line manually
55if [ -z "$gsdl2path" ]; then
56 autoset_gsdl_home gsdl2path
57fi
58
59# Setup Greenstone2, unless it has already been done
60if [ -z "$GSDLHOME" ]; then
61 pushd "$gsdl2path" > /dev/null
62 source ./setup.bash
63 popd > /dev/null
64fi
65
66# On MAC, need to tell apache to find and use its own libiconv<num>.dylib
67# If gs2-server.sh is run from GLI, we can't just test for the existence
68# of "apache-httpd", so use the full path (from GSDLHOME) to test it exists
69if test -e "$GSDLHOME/apache-httpd" ; then
70 echo "+Adding in executable path for apache-httpd"
71 PATH=$GSDLHOME/apache-httpd/$GSDLOS/bin:$PATH
72 export PATH
73
74 if test "$GSDLOS" = "linux" ; then
75 LD_LIBRARY_PATH="$GSDLHOME/apache-httpd/$GSDLOS/lib:$LD_LIBRARY_PATH"
76 export LD_LIBRARY_PATH
77 elif test "$GSDLOS" = "darwin" ; then
78 DYLD_LIBRARY_PATH="$GSDLHOME/apache-httpd/$GSDLOS/lib:$DYLD_LIBRARY_PATH"
79 export DYLD_LIBRARY_PATH
80 fi
81fi
82
83# First test that there is actually something that can be run...
84# Exit if the apache-httpd folder doesn't exist for some reason
85# (The errors reported when the apache webserver does not exist
86# in the correct location are not at all helpful).
87if [ ! -d "$GSDLHOME/apache-httpd" ]; then
88 echo ""
89 echo "UNABLE TO CONTINUE: There is no apache-httpd directory."
90 echo "It does not look like the local apache webserver has been installed."
91 echo "Exiting..."
92 echo ""
93 exit 1
94fi
95
96# If there's no llssite.cfg file, copy from the template
97if [ ! -e "$GSDLHOME/llssite.cfg" ]; then
98 if [ -e "$GSDLHOME/llssite.cfg.in" ]; then
99 cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg"
100 else
101 echo "Warning: could not find llssite.cfg.in to create llssite.cfg from."
102 fi
103fi
104
105## ---- Determine JAVA_HOME ----
106# Set this to true if you want the Greenstone server interface to run in the background
107# and not print any error messages to the x-term.
108silent=
109
110# JRE_HOME or JAVA_HOME must be set correctly to run this program
111search4j -m $java_min_version &> /dev/null
112# for some reason, Mac requires an echo after the above
113echo
114if [ "$?" == "0" ]; then
115 # In Java code, '...getResourceAsStream("build.properties")'
116 # needs up to be in the right directory when run
117 pushd "$gsdl2path" > /dev/null
118
119
120 #CLASSPATH
121 if [ `isinpath "$CLASSPATH" "$GSDLHOME/lib/java"` == "false" ]; then
122 CLASSPATH="$GSDLHOME/lib/java:$CLASSPATH"
123 for JARFILE in lib/java/*.jar; do
124 CLASSPATH="$CLASSPATH:$GSDLHOME/$JARFILE"
125 done
126 export CLASSPATH
127 echo " - Adjusted CLASSPATH"
128
129 else
130 echo " - CLASSPATH already correct"
131 fi
132
133 ## ---- Check Java ----
134 # call the script with source, so that we have the variables it sets ($javapath)
135 exit_status=0
136 source ./findjava.sh "$serverlang" "$PROGNAME"
137 exit_status=$?
138 if [ "$exit_status" -eq 1 ]; then
139 exit 1;
140 fi
141 export PATH=$javahome/bin:$PATH
142
143 # some informative messages to direct the users to the logs
144 if [ "$serverlang" == "en" -o "x$serverlang" == "x" ]; then
145 echo "***************************************************************"
146 echo "Starting the Greenstone Server Interface (GSI)..."
147 echo
148 echo "Server log messages go to:"
149 echo " $GSDLHOME/etc/logs-gsi/server.log"
150 echo
151 echo "Using Apache web server located at:"
152 echo " $GSDLHOME/apache-httpd/$GSDLOS/bin/httpd"
153 echo "The Apache error log is at:"
154 echo " $GSDLHOME/apache-httpd/$GSDLOS/logs/error_log"
155 echo "The Apache configuration file template is at:"
156 echo " $GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf.in"
157 echo "This is used to generate:"
158 echo " $GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf"
159 echo " each time Enter Library is pressed or otherwise activated."
160 echo "***************************************************************"
161 echo
162 echo
163 fi
164
165 # -Xdock:name To set the name of the app in the MacOS Dock bar
166 # -Xdock:icon Path to the MacOS Doc icon (not necessary for GS)
167 custom_vm_args=""
168 if [ "$GSDLOS" = "darwin" ]; then
169 custom_vm_args="-Xdock:name=$PROGFULLNAME"
170 fi
171
172
173 if [ "x$silent" == "x" -o "x$silent" != "xtrue" ]; then
174 # verbose mode, show all output, but then we can't run the server interface in the background
175
176 "$javapath" $custom_vm_args org.greenstone.server.Server2 "$GSDLHOME" "$serverlang" $*
177 else
178 # If we launch the Greenstone Server Interface application in the background (with & at end)
179 # need to redirect any STDERR (STDOUT) output to /dev/null first, else output will hog the x-term.
180 "$javapath" $custom_vm_args org.greenstone.server.Server2 "$GSDLHOME" "$serverlang" $* > /dev/null &
181 fi
182
183 popd > /dev/null
184fi
185
Note: See TracBrowser for help on using the repository browser.