[1374] | 1 | #!/bin/sh |
---|
| 2 | # Copyright 2012 Georg-August-Universit�t G�ttingen, Germany |
---|
| 3 | # |
---|
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 5 | # you may not use this file except in compliance with the License. |
---|
| 6 | # You may obtain a copy of the License at |
---|
| 7 | # |
---|
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 9 | # |
---|
| 10 | # Unless required by applicable law or agreed to in writing, software |
---|
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 13 | # See the License for the specific language governing permissions and |
---|
| 14 | # limitations under the License. |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | # This script starts the autoquest-httpmonitoring proxy which is in the same folder as |
---|
| 19 | # this script |
---|
| 20 | |
---|
| 21 | # Absolute path to this script, e.g. /home/user/bin/foo.sh |
---|
| 22 | SCRIPT=$(readlink -f $0) |
---|
| 23 | |
---|
| 24 | # Find the autoquest-httpmonitor JAR-File and start in the folder of this script |
---|
| 25 | JAR_FILE=`find $(dirname $SCRIPT) -type f -name 'autoquest-httpmonitor-*.jar'` |
---|
| 26 | |
---|
| 27 | # Get the ProcessID of the autoquest-httpmonitoring proxy which is in the same folder as this script |
---|
| 28 | PID=$(ps ax | grep "$JAR_FILE" | grep -v ' grep ' | grep ' proxy ' | awk '{print $1 " " $7}') |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | # Check if this autoquest-httpmonitoring proxy is already running |
---|
| 32 | if [ ! -z "$PID" ]; then |
---|
| 33 | echo "autoquest-httpmonitoring proxy is already running with PID:$PID" |
---|
| 34 | exit 1 |
---|
| 35 | fi |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | HOME_DIR=`dirname $0` |
---|
| 40 | |
---|
| 41 | # Given the "java" executable as an argument, find JAVA_HOME |
---|
| 42 | find_java() { |
---|
| 43 | # First check if it is a JDK in the /usr/lib/jvm directory, or a symlink there. |
---|
| 44 | # The test is somewhat complicated due to the different ways the Java implementations |
---|
| 45 | # are set up with the alternatives system |
---|
| 46 | # e.g. |
---|
| 47 | # /usr/bin/java -> /etc/alternatives/java -> /usr/lib/jvm/java-1.5.0-sun/jre/bin/java |
---|
| 48 | # or |
---|
| 49 | # /usr/bin/java -> /etc/alternatives/java -> /usr/lib/jvm/java-gcj/bin/java -> /usr/bin/gij-4.2 |
---|
| 50 | |
---|
| 51 | JAVA_HOME=$1 |
---|
| 52 | while true ; do |
---|
| 53 | case $JAVA_HOME in |
---|
| 54 | /usr/lib/jvm/*) |
---|
| 55 | # Found it! Return the correct paremt directory. |
---|
| 56 | |
---|
| 57 | JAVA_HOME=`echo $JAVA_HOME | sed 's:\(/usr/lib/jvm/[^/]*\).*:\1:'` |
---|
| 58 | return |
---|
| 59 | ;; |
---|
| 60 | *) ;; |
---|
| 61 | esac |
---|
| 62 | |
---|
| 63 | if [ -h $JAVA_HOME ] ; then |
---|
| 64 | JAVA_HOME=`readlink $JAVA_HOME` |
---|
| 65 | else |
---|
| 66 | break |
---|
| 67 | fi |
---|
| 68 | done |
---|
| 69 | |
---|
| 70 | # Not found in the Debian alternatives system, so presumably |
---|
| 71 | # it is a user-installed JDK/JRE. Might as well be helpful |
---|
| 72 | # and try to find JAVA_HOME. |
---|
| 73 | |
---|
| 74 | # First try for a JDK: |
---|
| 75 | JAVA_HOME=`readlink -e $1` |
---|
| 76 | while [ `dirname $JAVA_HOME` != / ]; do |
---|
| 77 | if [ -e $JAVA_HOME/lib/tools.jar ]; then |
---|
| 78 | return |
---|
| 79 | fi |
---|
| 80 | |
---|
| 81 | JAVA_HOME=`dirname $JAVA_HOME` |
---|
| 82 | done |
---|
| 83 | |
---|
| 84 | # If we get here we did not find a JDK. Search again for a JRE: |
---|
| 85 | JAVA_HOME=`readlink -e $1` |
---|
| 86 | while [ `dirname $JAVA_HOME` != / ]; do |
---|
| 87 | if [ -e $JAVA_HOME/bin/java ]; then |
---|
| 88 | return |
---|
| 89 | fi |
---|
| 90 | |
---|
| 91 | JAVA_HOME=`dirname $JAVA_HOME` |
---|
| 92 | done |
---|
| 93 | |
---|
| 94 | # Nothing found; leave blank |
---|
| 95 | JAVA_HOME= |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | if [ -z "$JAVA_HOME" ] ; then |
---|
| 99 | if [ -r /etc/gentoo-release ] ; then |
---|
| 100 | JAVA_HOME=`java-config --jre-home` |
---|
| 101 | else |
---|
| 102 | # Debian patch - search for preferred JRE |
---|
| 103 | if [ -n "$JAVACMD" ] ; then |
---|
| 104 | find_java "$JAVACMD" |
---|
| 105 | else |
---|
| 106 | find_java `which java` |
---|
| 107 | fi |
---|
| 108 | fi |
---|
| 109 | fi |
---|
| 110 | |
---|
| 111 | if [ -z "$JAVACMD" ] ; then |
---|
| 112 | if [ -n "$JAVA_HOME" ] ; then |
---|
| 113 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then |
---|
| 114 | # IBM's JDK on AIX uses strange locations for the executables |
---|
| 115 | JAVACMD="$JAVA_HOME/jre/sh/java" |
---|
| 116 | else |
---|
| 117 | JAVACMD="$JAVA_HOME/bin/java" |
---|
| 118 | fi |
---|
| 119 | else |
---|
| 120 | JAVACMD="`which java`" |
---|
| 121 | fi |
---|
| 122 | fi |
---|
| 123 | |
---|
| 124 | if [ ! -x "$JAVACMD" ] ; then |
---|
| 125 | echo "Error: JAVA_HOME is not defined correctly." |
---|
| 126 | echo " We cannot execute $JAVACMD" |
---|
| 127 | exit 1 |
---|
| 128 | fi |
---|
| 129 | |
---|
| 130 | if [ -z "$JAVA_HOME" ] ; then |
---|
| 131 | echo "Warning: JAVA_HOME environment variable is not set." |
---|
| 132 | fi |
---|
| 133 | |
---|
| 134 | cd ${HOME_DIR} |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | if [ ! -f "$JAR_FILE" ] ; then |
---|
| 138 | echo "Error: Could not find executable jar file in distribution." |
---|
| 139 | echo " Execution aborted." |
---|
| 140 | exit 1 |
---|
| 141 | fi |
---|
| 142 | |
---|
| 143 | # ./log is the standard log file. If this folder does not exist |
---|
| 144 | # create it |
---|
| 145 | if [ ! -d "./log" ] ; then |
---|
| 146 | mkdir "./log" |
---|
| 147 | fi |
---|
| 148 | LOGDIR="./log" |
---|
| 149 | echo "Using LogDir ./log" |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | # Every output from the JAR File will be saved in the Console.log |
---|
| 153 | # &1 is stdout, &2 is stderr |
---|
| 154 | echo "Starting autoquest-httpmonitoring proxy" |
---|
| 155 | exec 3>&1 4>&2 >>"$LOGDIR"/console-proxy.log 2>&1 |
---|
| 156 | |
---|
| 157 | echo "" |
---|
| 158 | echo "starting HTML monitoring proxy" |
---|
| 159 | date |
---|
| 160 | echo "using java $JAVACMD" |
---|
| 161 | |
---|
| 162 | $JAVACMD -jar ${JAR_FILE} proxy $LOGDIR $1 $2 $3 2>&1 >> "$LOGDIR"/console-proxy.log & |
---|
| 163 | |
---|
| 164 | # restore stdout and stderr |
---|
| 165 | exec 1>&3 2>&4 |
---|