source: trunk/autoquest-htmlmonitor/bin/run.sh @ 1686

Last change on this file since 1686 was 1226, checked in by pharms, 11 years ago
  • corrected line endings
  • changed behavior so that the script returns directly after being called
  • Property svn:executable set to *
File size: 4.5 KB
Line 
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-htmlmonitor which is in the same folder as
19# this script
20
21# Absolute path to this script, e.g. /home/user/bin/foo.sh
22SCRIPT=$(readlink -f $0)
23
24# Find the autoquest-htmlmonitor JAR-File and start in the Folder of this Script
25JAR_FILE=`find $(dirname $SCRIPT) -type f -name 'autoquest-htmlmonitor-*.jar'`
26
27# Get the ProcessID of the autoquest-htmlmonitor which is in the same folder as this script
28PID=$(ps ax | grep "$JAR_FILE" | grep -v ' grep ' | awk '{print $1 " " $7}')
29
30
31# Check if this autoquest-htmlmonitor is already running
32if [ ! -z "$PID" ]; then
33  echo "autoquest-htmlmonitor is running with PID:$PID"
34  exit 1
35fi
36
37
38
39HOME_DIR=`dirname $0`
40
41# Given the "java" executable as an argument, find JAVA_HOME
42find_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
98if [ -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
109fi
110
111if [ -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
122fi
123
124if [ ! -x "$JAVACMD" ] ; then
125  echo "Error: JAVA_HOME is not defined correctly."
126  echo "  We cannot execute $JAVACMD"
127  exit 1
128fi
129
130if [ -z "$JAVA_HOME" ] ; then
131  echo "Warning: JAVA_HOME environment variable is not set."
132fi
133
134cd ${HOME_DIR}
135
136
137if [ ! -f "$JAR_FILE" ] ; then
138  echo "Error: Could not find executable jar file in distribution."
139  echo "  Execution aborted."
140  exit 1
141fi
142
143# If the logdir was given to the script: Use it but test if it exist
144# if not, create it
145if [ ! -z "$1" ] ; then
146  LOGDIR="$1"
147  if [ -d "$LOGDIR" ] ; then
148    echo "Using LogDir $LOGDIR"
149  else
150    echo "Creating Folder $LOGDIR"
151    mkdir "$LOGDIR"
152  fi
153else
154  # ./log is the standard log file. If this folder does not exist
155  # create it
156  if [ ! -d "./log" ] ; then
157     mkdir "./log"
158  fi
159  LOGDIR="./log"
160  echo "Using LogDir ./log"
161fi
162
163
164# Every output from the JAR File will be saved in the Console.log
165# &1 is stdout, &2 is stderr
166echo "Starting autoquest-htmlmonitor"
167exec 3>&1 4>&2 >>"$LOGDIR"/console.log 2>&1
168
169echo ""
170echo "starting HTML monitor"
171date
172echo "using java $JAVACMD"
173
174$JAVACMD -jar ${JAR_FILE} $LOGDIR $2 2>&1 >> "$LOGDIR"/console.log &
175
176# restore stdout and stderr
177exec 1>&3 2>&4
Note: See TracBrowser for help on using the repository browser.