| #!/bin/bash |
| # |
| # Licensed to the Apache Software Foundation (ASF) under one or more |
| # contributor license agreements. See the NOTICE file distributed with this |
| # work for additional information regarding copyright ownership. The ASF |
| # licenses this file to You under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| # License for the specific language governing permissions and limitations |
| # under the License. |
| # |
| set -e |
| set -u |
| |
| # Store working directory |
| ORIGWD=$(pwd) |
| |
| # ${BASH_SOURCE[0]} is the path to this file |
| SOURCE="${BASH_SOURCE[0]}" |
| # Set $BIN to the absolute, symlinkless path to $SOURCE's parent |
| while [ -h "$SOURCE" ]; do |
| BIN="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
| SOURCE="$(readlink "$SOURCE")" |
| [[ $SOURCE != /* ]] && SOURCE="$BIN/$SOURCE" |
| done |
| BIN="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
| # Set $CFG to $BIN/../conf |
| cd -P $BIN/../conf |
| CFG=$(pwd) |
| # Set $LIB to $BIN/../lib |
| cd -P $BIN/../lib |
| LIB=$(pwd) |
| # Set $LIB to $BIN/../ext |
| cd -P $BIN/../ext |
| EXT=$(pwd) |
| # Initialize classpath to $CFG |
| CP="$CFG" |
| # Add the slf4j-log4j12 binding |
| CP="$CP":$(find -L $LIB -name 'slf4j-log4j12*.jar' | sort | tr '\n' ':') |
| # Add the jars in $BIN/../lib that start with "hugegraph" |
| CP="$CP":$(find -L $LIB -name 'hugegraph*.jar' | sort | tr '\n' ':') |
| # Add the remaining jars in $BIN/../lib. |
| CP="$CP":$(find -L $LIB -name '*.jar' \ |
| \! -name 'hugegraph*' \ |
| \! -name 'slf4j-log4j12*.jar' | sort | tr '\n' ':') |
| # Add the jars in $BIN/../ext (at any subdirectory depth) |
| CP="$CP":$(find -L $EXT -name '*.jar' | sort | tr '\n' ':') |
| |
| # (Cygwin only) Use ; classpath separator and reformat paths for Windows ("C:\foo") |
| [[ $(uname) = CYGWIN* ]] && CP="$(cygpath -p -w "$CP")" |
| |
| export CLASSPATH="${CLASSPATH:-}:$CP" |
| |
| # Restore initial working directory of this script |
| cd "$ORIGWD" |
| |
| # Find Java |
| if [ -z "${JAVA_HOME:-}" ]; then |
| JAVA="java -server" |
| else |
| JAVA="$JAVA_HOME/bin/java -server" |
| fi |
| |
| # Set default message threshold for Log4j Gremlin's console appender |
| if [ -z "${GREMLIN_LOG_LEVEL:-}" ]; then |
| GREMLIN_LOG_LEVEL=WARN |
| fi |
| |
| # Script debugging is disabled by default, but can be enabled with -l |
| # TRACE or -l DEBUG or enabled by exporting |
| # SCRIPT_DEBUG=nonemptystring to gremlin-console.sh's environment |
| if [ -z "${SCRIPT_DEBUG:-}" ]; then |
| SCRIPT_DEBUG= |
| fi |
| |
| # Initialize the profiling switch |
| PROFILING_ENABLED=false |
| |
| # Process options |
| MAIN_CLASS=org.apache.tinkerpop.gremlin.console.Console |
| while getopts "lpv" opt; do |
| case "$opt" in |
| # class ScriptExecutor has been Deprecated. |
| # reference https://tinkerpop.apache.org/javadocs/3.2.3/full/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.html |
| l) eval GREMLIN_LOG_LEVEL=\$$OPTIND |
| OPTIND="$(( $OPTIND + 1 ))" |
| if [ "$GREMLIN_LOG_LEVEL" = "TRACE" -o \ |
| "$GREMLIN_LOG_LEVEL" = "DEBUG" ]; then |
| SCRIPT_DEBUG=y |
| fi |
| ;; |
| p) PROFILING_ENABLED=true |
| ;; |
| v) MAIN_CLASS=org.apache.hugegraph.core.hugegraph |
| esac |
| done |
| |
| # Remove processed options from $@. Anything after -e is preserved by the break;; in the case |
| shift $(( $OPTIND - 1 )) |
| |
| if [ -z "${HADOOP_GREMLIN_LIBS:-}" ]; then |
| export HADOOP_GREMLIN_LIBS="$LIB" |
| fi |
| |
| if [ -z "${JAVA_OPTIONS:-}" ]; then |
| JAVA_OPTIONS="-Dtinkerpop.ext=$EXT -Dlog4j.configurationFile=conf/log4j2.xml -Dgremlin.log4j.level=$GREMLIN_LOG_LEVEL -javaagent:$LIB/jamm-0.3.0.jar" |
| fi |
| |
| if [ "$PROFILING_ENABLED" = true ]; then |
| JAVA_OPTIONS="$JAVA_OPTIONS -Dtinkerpop.profiling=true" |
| fi |
| |
| if [ -n "$SCRIPT_DEBUG" ]; then |
| echo "CLASSPATH: $CLASSPATH" |
| set -x |
| fi |
| |
| # Start the JVM, execute the application, and return its exit code |
| exec $JAVA $JAVA_OPTIONS $MAIN_CLASS "$@" |