Skip to content

Commit aa0d8da

Browse files
authored
fix(dist): start server with java 11 (#2020)
1 parent 57462b0 commit aa0d8da

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if [[ $# -lt 3 ]]; then
3232
fi
3333

3434
BIN=$(abs_path)
35-
TOP="$(cd $BIN/../ && pwd)"
35+
TOP="$(cd "$BIN"/../ && pwd)"
3636
CONF="$TOP/conf"
3737
LIB="$TOP/lib"
3838
EXT="$TOP/ext"
@@ -41,7 +41,7 @@ LOGS="$TOP/logs"
4141
OUTPUT=${LOGS}/hugegraph-server.log
4242

4343
export HUGEGRAPH_HOME="$TOP"
44-
. ${BIN}/util.sh
44+
. "${BIN}"/util.sh
4545

4646
GREMLIN_SERVER_CONF="$1"
4747
REST_SERVER_CONF="$2"
@@ -58,13 +58,13 @@ elif [[ $# -eq 5 ]]; then
5858
GC_OPTION="$5"
5959
fi
6060

61-
ensure_path_writable $LOGS
62-
ensure_path_writable $PLUGINS
61+
ensure_path_writable "$LOGS"
62+
ensure_path_writable "$PLUGINS"
6363

64-
# The maximum and minium heap memory that service can use
64+
# The maximum and minimum heap memory that service can use
6565
MAX_MEM=$((32 * 1024))
6666
MIN_MEM=$((1 * 512))
67-
EXPECT_JDK_VERSION=1.8
67+
MIN_JAVA_VERSION=8
6868

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

8787
# Change to $BIN's parent
88-
cd ${TOP}
88+
cd "${TOP}" || exit 1;
8989

90-
# Find Java
90+
# Find java & enable server option
9191
if [ "$JAVA_HOME" = "" ]; then
9292
JAVA="java -server"
9393
else
9494
JAVA="$JAVA_HOME/bin/java -server"
9595
fi
9696

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

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

0 commit comments

Comments
 (0)