diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh index 79850eecc2..ff8addd718 100755 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh @@ -17,12 +17,36 @@ # Script structure inspired from Apache Karaf and other Apache projects with similar startup approaches -SCRIPT_DIR=$(dirname "$0") -SCRIPT_NAME=$(basename "$0") +# Discover the path of the file + + +# Since MacOS X, FreeBSD and some other systems lack gnu readlink, we use a more portable +# approach based on following StackOverflow comment http://stackoverflow.com/a/1116890/888876 + +TARGET_FILE=$0 + +cd $(dirname $TARGET_FILE) +TARGET_FILE=$(basename $TARGET_FILE) + +# Iterate down a (possible) chain of symlinks +while [ -L "$TARGET_FILE" ] +do + TARGET_FILE=$(readlink $TARGET_FILE) + cd $(dirname $TARGET_FILE) + TARGET_FILE=$(basename $TARGET_FILE) +done + +# Compute the canonicalized name by finding the physical path +# for the directory we're in and appending the target file. +PHYS_DIR=`pwd -P` + +SCRIPT_DIR=$PHYS_DIR PROGNAME=$(basename "$0") . "$SCRIPT_DIR"/nifi-env.sh + + warn() { echo "${PROGNAME}: $*" }