Skip to content

Commit

Permalink
Do not require Java presence for RPM installation
Browse files Browse the repository at this point in the history
This allows for custom JDK to be used when running Trino
with launcher --jvm-dir argument.
  • Loading branch information
wendigo committed Dec 18, 2024
1 parent e1574bc commit 1c5e621
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 78 deletions.
10 changes: 0 additions & 10 deletions core/trino-server-rpm/src/main/rpm/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ install --directory --mode=755 /var/log/trino
# Populate node.id from uuidgen by replacing template with the node uuid
sed -i "s/\$(uuid-generated-nodeid)/$(cat /proc/sys/kernel/random/uuid)/g" /etc/trino/node.properties

# read /tmp/trino-rpm-install-java-home created during pre-install and save JAVA_HOME in env.sh at Trino config location
if [ -r /tmp/trino-rpm-install-java-home ]; then
JAVA_HOME=$(cat /tmp/trino-rpm-install-java-home)
target=/etc/trino/env.sh
sed -i "/^#JAVA_HOME=$/d" $target
if ! grep -q '^JAVA_HOME=' $target >/dev/null; then
echo "JAVA_HOME=$JAVA_HOME" >> $target
fi
fi

chown -R trino:trino /var/lib/trino
chown -R trino:trino /var/log/trino
chown -R trino:trino /etc/trino
68 changes: 0 additions & 68 deletions core/trino-server-rpm/src/main/rpm/preinstall
Original file line number Diff line number Diff line change
@@ -1,72 +1,4 @@
# Pre installation script

# Ensure that the proper version of Java exists on the system

java_version() {
# The one argument is the location of java (either $JAVA_HOME or a potential
# candidate for JAVA_HOME.
JAVA="$1"/bin/java
"$JAVA" -version 2>&1 | grep "\(java\|openjdk\) version" | awk '{ print substr($3, 2, length($3)-2); }'
}

check_if_correct_java_version() {

# If the string is empty return non-zero code. We don't want false positives if /bin/java is
# a valid java version because that will leave JAVA_HOME unset and the init.d scripts will
# use the default java version, which may not be the correct version.
if [ -z "$1" ]; then
return 1
fi

# The one argument is the location of java (either $JAVA_HOME or a potential
# candidate for JAVA_HOME).
JAVA_VERSION=$(java_version "$1")
JAVA_MAJOR=$(echo "$JAVA_VERSION" | cut -d'-' -f1 | cut -d'.' -f1)
if [ "$JAVA_MAJOR" -ge "23" ]; then
echo "$1" >/tmp/trino-rpm-install-java-home
return 0
else
return 1
fi
}

# if Java version of $JAVA_HOME is not correct, then try to find it again below
if ! check_if_correct_java_version "$JAVA_HOME"; then
java_found=false
for candidate in \
/usr/lib/jvm/java-23-* \
/usr/lib/jvm/zulu-23 \
/usr/lib/jvm/temurin-23 \
/usr/lib/jvm/temurin-23-* \
/usr/lib/jvm/default-java \
/usr/java/default \
/ \
/usr; do
if [ -e "$candidate"/bin/java ]; then
if check_if_correct_java_version "$candidate"; then
java_found=true
break
fi
fi
done
fi

# if no appropriate java found
if [ "$java_found" = false ]; then
cat 1>&2 <<EOF
+======================================================================+
| Error: Required Java version could not be found |
+----------------------------------------------------------------------+
| JDK 23 was not detected. |
| Recommended JDK distribution is Eclipse Temurin. |
| Installation guide: https://adoptium.net/installation/linux/ |
| |
| NOTE: This script will attempt to find Java whether you install |
| using the binary or the RPM based installer. |
+======================================================================+
EOF
exit 1
fi

getent group trino >/dev/null || /usr/sbin/groupadd -r trino
getent passwd trino >/dev/null || /usr/sbin/useradd --comment "Trino" -s /sbin/nologin -g trino -r -d /var/lib/trino trino
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private void testInstall(String temurinReleaseName, String javaHome, String expe
.withCommand("sh", "-xeuc", command)
.withCreateContainerCmdModifier(modifier -> modifier
.withHostConfig(modifier.getHostConfig().withInit(true)))
.withEnv("JAVA_HOME", javaHome)
.waitingFor(forLogMessage(".*SERVER STARTED.*", 1).withStartupTimeout(Duration.ofMinutes(5)))
.start();
QueryRunner queryRunner = new QueryRunner(container.getHost(), container.getMappedPort(8080));
Expand Down Expand Up @@ -137,6 +138,7 @@ private void testUninstall(String temurinReleaseName, String javaHome)
try (GenericContainer<?> container = new GenericContainer<>(BASE_IMAGE)) {
container.withFileSystemBind(rpmHostPath, rpm, BindMode.READ_ONLY)
.withCommand("sh", "-xeuc", installAndStartTrino)
.withEnv("JAVA_HOME", javaHome)
.withCreateContainerCmdModifier(modifier -> modifier
.withHostConfig(modifier.getHostConfig().withInit(true)))
.waitingFor(forLogMessage(".*SERVER STARTED.*", 1).withStartupTimeout(Duration.ofMinutes(5)))
Expand Down

0 comments on commit 1c5e621

Please sign in to comment.