Last active
March 21, 2021 21:28
-
-
Save kwilczynski/5209680 to your computer and use it in GitHub Desktop.
Detect Java JVM home in Bash shell before starting Mesos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
java_binary_link="/usr/bin/java" | |
java_library="libjvm.so" | |
library_paths=( | |
/jre/lib/amd64/server | |
/jre/lib/amd64/client | |
/usr/lib | |
/lib | |
) | |
if [ -z "$java_home" ] || [ ! -d "$java_home" ]; then | |
JAVA_HOME=$(dirname $(dirname $(dirname $(readlink -f $java_binary_link)))) | |
if [ ! -d $java_home ]; then | |
JAVA_HOME="/usr/lib/jvm/default-java" | |
fi | |
fi | |
if ! /sbin/ldconfig -p | /bin/grep $java_library > /dev/null 2>&1 ; then | |
for path in ${library_paths[@]}; do | |
library_path=$(echo $"${JAVA_HOME}/${path}" | tr -s '/') | |
if [ -f "${library_path}/${java_library}" ]; then | |
LD_LIBRARY_PATH="${library_path}:${LD_LIBRARY_PATH}" | |
break | |
fi | |
done | |
fi | |
export JAVA_HOME LD_LIBRARY_PATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related to https://gist.github.com/kwilczynski/5209531.