1#!/bin/sh
2
3DIRNAME=`dirname "$0"`
4PROGNAME=`basename "$0"`
5GREP="grep"
6SERVER_OPTS=""
7
8# Parsing incoming parameters
9while [ "$#" -gt 0 ]
10do
11    case "$1" in
12      -secmgr)
13          SECMGR="true"
14          ;;
15      -Djava.security.manager)
16          echo "ERROR: The use of -Djava.security.manager has been removed. Please use the -secmgr command line argument or SECMGR=true environment variable."
17          exit 1
18          ;;
19      --)
20          shift
21          break;;
22      *)
23          SERVER_OPTS="$SERVER_OPTS '$1'"
24          ;;
25    esac
26    shift
27done
28
29# Use the maximum available, or set MAX_FD != -1 to use that
30MAX_FD="maximum"
31
32# OS specific support (must be 'true' or 'false').
33cygwin=false;
34darwin=false;
35linux=false;
36case "`uname`" in
37    CYGWIN*)
38        cygwin=true
39        ;;
40
41    Darwin*)
42        darwin=true
43        ;;
44
45    Linux)
46        linux=true
47        ;;
48esac
49
50# Read an optional running configuration file
51if [ "x$RUN_CONF" = "x" ]; then
52    RUN_CONF="$DIRNAME/appclient.conf"
53fi
54if [ -r "$RUN_CONF" ]; then
55    . "$RUN_CONF"
56fi
57
58# For Cygwin, ensure paths are in UNIX format before anything is touched
59if $cygwin ; then
60    [ -n "$JBOSS_HOME" ] &&
61        JBOSS_HOME=`cygpath --unix "$JBOSS_HOME"`
62    [ -n "$JAVA_HOME" ] &&
63        JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
64    [ -n "$JAVAC_JAR" ] &&
65        JAVAC_JAR=`cygpath --unix "$JAVAC_JAR"`
66fi
67
68# Setup JBOSS_HOME
69RESOLVED_JBOSS_HOME=`cd "$DIRNAME/.."; pwd`
70if [ "x$JBOSS_HOME" = "x" ]; then
71    # get the full path (without any relative bits)
72    JBOSS_HOME=$RESOLVED_JBOSS_HOME
73else
74 SANITIZED_JBOSS_HOME=`cd "$JBOSS_HOME"; pwd`
75 if [ "$RESOLVED_JBOSS_HOME" != "$SANITIZED_JBOSS_HOME" ]; then
76   echo "WARNING JBOSS_HOME may be pointing to a different installation - unpredictable results may occur."
77   echo ""
78 fi
79fi
80export JBOSS_HOME
81
82# Setup the JVM
83if [ "x$JAVA" = "x" ]; then
84    if [ "x$JAVA_HOME" != "x" ]; then
85        JAVA="$JAVA_HOME/bin/java"
86    else
87        JAVA="java"
88    fi
89fi
90
91# Check for -d32/-d64 in JAVA_OPTS
92JVM_OPTVERSION="-version"
93JVM_D64_OPTION=`echo $JAVA_OPTS | $GREP "\-d64"`
94JVM_D32_OPTION=`echo $JAVA_OPTS | $GREP "\-d32"`
95test "x$JVM_D64_OPTION" != "x" && JVM_OPTVERSION="-d64 $JVM_OPTVERSION"
96test "x$JVM_D32_OPTION" != "x" && JVM_OPTVERSION="-d32 $JVM_OPTVERSION"
97
98# If -server not set in JAVA_OPTS, set it, if supported
99SERVER_SET=`echo $JAVA_OPTS | $GREP "\-server"`
100if [ "x$SERVER_SET" = "x" ]; then
101
102    # Check for SUN(tm) JVM w/ HotSpot support
103    if [ "x$HAS_HOTSPOT" = "x" ]; then
104        HAS_HOTSPOT=`"$JAVA" $JVM_OPTVERSION -version 2>&1 | $GREP -i HotSpot`
105    fi
106
107    # Check for OpenJDK JVM w/server support
108    if [ "x$HAS_OPENJDK_" = "x" ]; then
109        HAS_OPENJDK=`"$JAVA" $JVM_OPTVERSION 2>&1 | $GREP -i OpenJDK`
110    fi
111
112    # Enable -server if we have Hotspot or OpenJDK, unless we can't
113    if [ "x$HAS_HOTSPOT" != "x" -o "x$HAS_OPENJDK" != "x" ]; then
114        # MacOS does not support -server flag
115        if [ "$darwin" != "true" ]; then
116            JAVA_OPTS="-server $JAVA_OPTS"
117            JVM_OPTVERSION="-server $JVM_OPTVERSION"
118        fi
119    fi
120else
121    JVM_OPTVERSION="-server $JVM_OPTVERSION"
122fi
123
124if [ "x$JBOSS_MODULEPATH" = "x" ]; then
125    JBOSS_MODULEPATH="$JBOSS_HOME/modules"
126fi
127
128# For Cygwin, switch paths to Windows format before running java
129if $cygwin; then
130    JBOSS_HOME=`cygpath --path --windows "$JBOSS_HOME"`
131    JBOSS_MODULEPATH=`cygpath --path --windows "$JBOSS_MODULEPATH"`
132fi
133
134# Process the JAVA_OPTS failing if the java.security.manager is set.
135SECURITY_MANAGER_SET=`echo $JAVA_OPTS | $GREP "java\.security\.manager"`
136if [ "x$SECURITY_MANAGER_SET" != "x" ]; then
137    echo "ERROR: The use of -Djava.security.manager has been removed. Please use the -secmgr command line argument or SECMGR=true environment variable."
138    exit 1
139fi
140
141# Set up the module arguments
142MODULE_OPTS=""
143if [ "$SECMGR" = "true" ]; then
144    MODULE_OPTS="-secmgr";
145fi
146
147CLASSPATH="$CLASSPATH:\""$JBOSS_HOME"\"/jboss-modules.jar"
148# Execute the JVM in the foreground
149eval \"$JAVA\" $JAVA_OPTS \
150 -cp "$CLASSPATH" \
151 \"-Dorg.jboss.boot.log.file="$JBOSS_HOME"/appclient/log/appclient.log\" \
152 \"-Dlogging.configuration=file:"$JBOSS_HOME"/appclient/configuration/logging.properties\" \
153 org.jboss.modules.Main \
154 $MODULE_OPTS \
155 -mp \""${JBOSS_MODULEPATH}"\" \
156 org.jboss.as.appclient \
157 -Djboss.home.dir=\""$JBOSS_HOME"\" \
158 -Djboss.server.base.dir=\""$JBOSS_HOME"/appclient\" \
159 "$SERVER_OPTS"
160JBOSS_STATUS=$?
161exit $JBOSS_STATUS