Skip to content

Commit

Permalink
fix(dist): start server with java 11 (#2020)
Browse files Browse the repository at this point in the history
  • Loading branch information
imbajin authored Nov 20, 2022
1 parent 57462b0 commit aa0d8da
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [[ $# -lt 3 ]]; then
fi

BIN=$(abs_path)
TOP="$(cd $BIN/../ && pwd)"
TOP="$(cd "$BIN"/../ && pwd)"
CONF="$TOP/conf"
LIB="$TOP/lib"
EXT="$TOP/ext"
Expand All @@ -41,7 +41,7 @@ LOGS="$TOP/logs"
OUTPUT=${LOGS}/hugegraph-server.log

export HUGEGRAPH_HOME="$TOP"
. ${BIN}/util.sh
. "${BIN}"/util.sh

GREMLIN_SERVER_CONF="$1"
REST_SERVER_CONF="$2"
Expand All @@ -58,13 +58,13 @@ elif [[ $# -eq 5 ]]; then
GC_OPTION="$5"
fi

ensure_path_writable $LOGS
ensure_path_writable $PLUGINS
ensure_path_writable "$LOGS"
ensure_path_writable "$PLUGINS"

# The maximum and minium heap memory that service can use
# The maximum and minimum heap memory that service can use
MAX_MEM=$((32 * 1024))
MIN_MEM=$((1 * 512))
EXPECT_JDK_VERSION=1.8
MIN_JAVA_VERSION=8

# Add the slf4j-log4j12 binding
CP=$(find -L $LIB -name 'log4j-slf4j-impl*.jar' | sort | tr '\n' ':')
Expand All @@ -85,19 +85,18 @@ CP="$CP":$(find -L $PLUGINS -name '*.jar' | sort | tr '\n' ':')
export CLASSPATH="${CLASSPATH:-}:$CP"

# Change to $BIN's parent
cd ${TOP}
cd "${TOP}" || exit 1;

# Find Java
# Find java & enable server option
if [ "$JAVA_HOME" = "" ]; then
JAVA="java -server"
else
JAVA="$JAVA_HOME/bin/java -server"
fi

JAVA_VERSION=$($JAVA -version 2>&1 | awk 'NR==1{gsub(/"/,""); print $3}' \
| awk -F'_' '{print $1}')
if [[ $? -ne 0 || $JAVA_VERSION < $EXPECT_JDK_VERSION ]]; then
echo "Please make sure that the JDK is installed and the version >= $EXPECT_JDK_VERSION" \
JAVA_VERSION=$($JAVA -version 2>&1 | head -1 | cut -d'"' -f2 | sed 's/^1\.//' | cut -d'.' -f1)
if [[ $? -ne 0 || $JAVA_VERSION -lt $MIN_JAVA_VERSION ]]; then
echo "Make sure the JDK is installed and the version >= $MIN_JAVA_VERSION, current is $JAVA_VERSION" \
>> ${OUTPUT}
exit 1
fi
Expand All @@ -106,8 +105,7 @@ fi
if [ "$JAVA_OPTIONS" = "" ]; then
XMX=$(calc_xmx $MIN_MEM $MAX_MEM)
if [ $? -ne 0 ]; then
echo "Failed to start HugeGraphServer, requires at least ${MIN_MEM}m free memory" \
>> ${OUTPUT}
echo "Failed to start HugeGraphServer, requires at least ${MIN_MEM}MB free memory" >> ${OUTPUT}
exit 1
fi
JAVA_OPTIONS="-Xms${MIN_MEM}m -Xmx${XMX}m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${LOGS} ${USER_OPTION}"
Expand All @@ -117,7 +115,7 @@ if [ "$JAVA_OPTIONS" = "" ]; then
# -Xloggc:./logs/gc.log -XX:+PrintHeapAtGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps"
fi

if [[ $JAVA_VERSION > "1.9" ]]; then
if [[ $JAVA_VERSION -gt 9 ]]; then
JAVA_OPTIONS="${JAVA_OPTIONS} --add-exports=java.base/jdk.internal.reflect=ALL-UNNAMED \
--add-modules=jdk.unsupported \
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED "
Expand Down

0 comments on commit aa0d8da

Please sign in to comment.