From 1c5e6213a863cb5851bb59f9b7c7fff63e82b528 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 17 Dec 2024 22:29:50 +0100 Subject: [PATCH] Do not require Java presence for RPM installation This allows for custom JDK to be used when running Trino with launcher --jvm-dir argument. --- .../trino-server-rpm/src/main/rpm/postinstall | 10 --- core/trino-server-rpm/src/main/rpm/preinstall | 68 ------------------- .../java/io/trino/server/rpm/ServerIT.java | 2 + 3 files changed, 2 insertions(+), 78 deletions(-) diff --git a/core/trino-server-rpm/src/main/rpm/postinstall b/core/trino-server-rpm/src/main/rpm/postinstall index 3764fa7455c3..f0261473f117 100644 --- a/core/trino-server-rpm/src/main/rpm/postinstall +++ b/core/trino-server-rpm/src/main/rpm/postinstall @@ -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 diff --git a/core/trino-server-rpm/src/main/rpm/preinstall b/core/trino-server-rpm/src/main/rpm/preinstall index d0a7e90d2c21..4ac7fc7a6fa7 100644 --- a/core/trino-server-rpm/src/main/rpm/preinstall +++ b/core/trino-server-rpm/src/main/rpm/preinstall @@ -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 </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 diff --git a/core/trino-server-rpm/src/test/java/io/trino/server/rpm/ServerIT.java b/core/trino-server-rpm/src/test/java/io/trino/server/rpm/ServerIT.java index 93e89aebfef5..946d3734883b 100644 --- a/core/trino-server-rpm/src/test/java/io/trino/server/rpm/ServerIT.java +++ b/core/trino-server-rpm/src/test/java/io/trino/server/rpm/ServerIT.java @@ -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)); @@ -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)))