root/main/trunk/greenstone2/gs2-server.sh @ 23648

Revision 23648, 5.5 KB (checked in by ak19, 9 years ago)

Related to the changes to gs2-server.sh committed for Mac: for Linux, am also adding in the apache-lib to LD_LIBRARY_PATH in gs2-server rather than setup.bash. Reinstating these recent changes for Linux, but in the correct location this time to correct a previous oversight: only makes sense to refer to GSDLHOME after the gs2-server.sh script has sourced setup.bash.

  • Property svn:executable set to *
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(?).dylib
67if test -e apache-httpd ; then
68    echo "+Adding in executable path for apache-httpd"
69    PATH=$GSDLHOME/apache-httpd/$GSDLOS/bin:$PATH
70    export PATH
71   
72    if test "$GSDLOS" = "linux" ; then
73    LD_LIBRARY_PATH="$GSDLHOME/apache-httpd/$GSDLOS/lib:$LD_LIBRARY_PATH"
74    export LD_LIBRARY_PATH
75    elif test "$GSDLOS" = "darwin" ; then     
76    DYLD_LIBRARY_PATH="$GSDLHOME/apache-httpd/$GSDLOS/lib:$DYLD_LIBRARY_PATH"
77    export DYLD_LIBRARY_PATH
78    fi
79fi
80
81# First test that there is actually something that can be run...
82# Exit if the apache-httpd folder doesn't exist for some reason
83# (The errors reported when the apache webserver does not exist
84# in the correct location are not at all helpful).
85if [ ! -d "$GSDLHOME/apache-httpd" ]; then
86    echo ""
87    echo "UNABLE TO CONTINUE: There is no apache-httpd directory."
88    echo "It does not look like the local apache webserver has been installed."
89    echo "Exiting..."
90    echo ""
91    exit 1
92fi
93
94# If there's no llssite.cfg file, copy from the template
95if [ ! -e "$GSDLHOME/llssite.cfg" ]; then
96    if [ -e "$GSDLHOME/llssite.cfg.in" ]; then
97    cp "$GSDLHOME/llssite.cfg.in" "$GSDLHOME/llssite.cfg"
98    else
99    echo "Warning: could not find llssite.cfg.in to create llssite.cfg from."
100    fi
101fi
102
103##  ---- Determine JAVA_HOME ----
104# Set this to true if you want the Greenstone server interface to run in the background
105# and not print any error messages to the x-term.
106silent=
107
108# JRE_HOME or JAVA_HOME must be set correctly to run this program
109search4j -m $java_min_version &> /dev/null
110# for some reason, Mac requires an echo after the above
111echo
112if [ "$?" == "0" ]; then
113    # In Java code, '...getResourceAsStream("build.properties")'
114    # needs up to be in the right directory when run
115    pushd "$gsdl2path" > /dev/null
116
117
118    #CLASSPATH
119    if [ `isinpath "$CLASSPATH" "$GSDLHOME/lib/java"` == "false" ]; then
120        CLASSPATH="$GSDLHOME/lib/java:$CLASSPATH"
121        for JARFILE in lib/java/*.jar; do
122            CLASSPATH="$CLASSPATH:$GSDLHOME/$JARFILE"
123        done
124        export CLASSPATH
125        echo "  - Adjusted CLASSPATH"
126
127    else
128        echo "  - CLASSPATH already correct"
129    fi
130
131    ## ---- Check Java ----
132    # call the script with source, so that we have the variables it sets ($javapath)
133    exit_status=0
134    source ./findjava.sh "$serverlang" "$PROGNAME"
135    exit_status=$?
136    if [ "$exit_status" -eq 1 ]; then
137        exit 1;
138    fi
139    export PATH=$javahome/bin:$PATH
140
141    # some informative messages to direct the users to the logs
142    if [ "$serverlang" == "en" -o "x$serverlang" == "x" ]; then
143    echo "***************************************************************"
144    echo "Starting the Greenstone Server Interface (GSI)..."
145    echo
146    echo "Server log messages go to:"
147    echo "   $GSDLHOME/etc/logs-gsi/server.log"
148    echo
149    echo "Using Apache web server located at:"
150    echo "   $GSDLHOME/apache-httpd/$GSDLOS/bin/httpd"
151    echo "The Apache error log is at:"
152    echo "   $GSDLHOME/apache-httpd/$GSDLOS/logs/error_log"
153    echo "The Apache configuration file template is at:"
154    echo "   $GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf.in"
155    echo "This is used to generate:"
156    echo "   $GSDLHOME/apache-httpd/$GSDLOS/conf/httpd.conf"
157    echo "   each time Enter Library is pressed or otherwise activated."
158    echo "***************************************************************"
159    echo
160    echo
161    fi
162
163    # -Xdock:name      To set the name of the app in the MacOS Dock bar
164    # -Xdock:icon      Path to the MacOS Doc icon (not necessary for GS)   
165    custom_vm_args=""
166    if [ "$GSDLOS" = "darwin" ]; then
167        custom_vm_args="-Xdock:name=$PROGFULLNAME"
168    fi
169
170
171    if [ "x$silent" == "x" -o "x$silent" != "xtrue" ]; then
172        # verbose mode, show all output, but then we can't run the server interface in the background
173   
174    "$javapath" $custom_vm_args org.greenstone.server.Server2 "$GSDLHOME" "$serverlang" $*
175    else
176        # If we launch the Greenstone Server Interface application in the background (with & at end)
177        # need to redirect any STDERR (STDOUT) output to /dev/null first, else output will hog the x-term.
178    "$javapath" $custom_vm_args org.greenstone.server.Server2 "$GSDLHOME" "$serverlang" $* > /dev/null &
179    fi
180
181    popd > /dev/null
182fi
183
Note: See TracBrowser for help on using the browser.