Skip to content

feat(startup_scripts): add looker21 script for JDK 21 support#32

Merged
mnvsngv merged 2 commits into
looker-open-source:mainfrom
mnvsngv:add-looker21
Jul 14, 2026
Merged

feat(startup_scripts): add looker21 script for JDK 21 support#32
mnvsngv merged 2 commits into
looker-open-source:mainfrom
mnvsngv:add-looker21

Conversation

@mnvsngv

@mnvsngv mnvsngv commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Description

Add a new startup script looker21 specifically for running Looker on JDK 21. This script:

  • Enforces JDK 21 version check.
  • Adds JVM flags required for JRuby compatibility on JDK 21:
    • --add-opens=java.base/sun.nio.ch=ALL-UNNAMED
    • --add-opens=java.base/java.io=ALL-UNNAMED
    • --add-opens=java.base/java.nio=ALL-UNNAMED
  • Removes obsolete Nashorn flags.

This allows on-premise customers to transition to JDK 21.

High-level Diff

The script has been copied from looker11, here is the diff between the 2 files generated by running git diff --no-index startup_scripts/looker11 startup_scripts/looker21:

--- startup_scripts/looker11	2026-07-14 13:06:16.226106539 -0700
+++ startup_scripts/looker21	2026-07-14 13:11:58.913959370 -0700
@@ -1,14 +1,14 @@
 #!/bin/sh
 
 #
-# This is the startup script for Looker using OpenJDK11.  Looker supports
-# OpenJDK11 starting with the 7.16 release
+# This is the startup script for Looker using OpenJDK 21.  Looker supports
+# OpenJDK 21 starting with the 26.4 release
 #
 
-JAVA_VER=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
-if [ "$JAVA_VER" -ne 11 ]; then
+JAVA_VER=$(java -version 2>&1 | grep 'version "' | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
+if [ "$JAVA_VER" -ne 21 ]; then
   WHERE=`which java`
-  echo "This script runs with OpenJDK11, your executable $WHERE has Java major version $JAVA_VER"
+  echo "This script runs with OpenJDK 21, your executable $WHERE has Java major version $JAVA_VER"
   exit 1
 fi
 
@@ -28,10 +28,8 @@
 # args increase module visibility and so suppress the output
 REFLECTIVE_ACCESS_ARGS="--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED"
 
-# Disable optimistic typing in Nashorn (the JDK Javascript interpreter).
-# This flag defaults to True in JDK 11 (previously False in JDK 8) and in this
-# configuration it causes large spikes in Metaspace use in some circumstances.
-export NASHORN_ARGS="-Dnashorn.args=--optimistic-types=false"
+# JVM flags for JDK 21 module visibility (primarily for JRuby compatibility)
+JDK21_MODULE_ARGS="--add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED"
 
 # to set up JMX monitoring, add JMXARGS to JAVAARGS
 JAVAARGS=""
@@ -76,7 +74,7 @@
   -Xms$JAVAMEM -Xmx$JAVAMEM \
   -Xlog:gc*,gc+ref=debug,gc+heap=debug,gc+age=debug:file=/tmp/gc-%p-%t.log:tags,uptime,time,level:filecount=7,filesize=10m \
   ${REFLECTIVE_ACCESS_ARGS} \
-  ${NASHORN_ARGS} \
+  ${JDK21_MODULE_ARGS} \
   ${JAVAARGS} \
   -jar looker.jar start ${LOOKERARGS}

Script Improvements

Gemini suggested a bunch of improvements, which I've incorporated. I'm presenting those diffs seprately in this section.

Robust Java Version Check

Handles cases where the version variable might be empty (e.g., if Java is not installed/configured), preventing shell syntax errors.

@@ -9,3 +9,3 @@
-if [ "$JAVA_VER" -ne 21 ]; then
+if [ "$JAVA_VER" != "21" ]; then
   WHERE=`which java`

Safe Directory Change

Ensures the script aborts immediately if it cannot access the Looker directory, rather than executing commands in the wrong path. Quotes the path to handle spaces safely.

@@ -15,3 +15,3 @@
-cd $HOME/looker
+cd "$HOME/looker" || exit 1

Robust Memory Calculation with Fallback

Modernizes the math using POSIX arithmetic ($((...))) instead of expr, and adds a fallback memory allocation (2048m) if /proc/meminfo is unreadable (e.g., on macOS or in some containerized environments).

@@ -18,3 +18,7 @@
-MEM=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`
-JM=`expr $MEM \* 6 / 10`
-JAVAMEM="${JM}k"
+MEM=$(cat /proc/meminfo 2>/dev/null | grep MemTotal | awk '{print $2}')
+if [ -n "$MEM" ]; then
+  JM=$((MEM * 6 / 10))
+  JAVAMEM="${JM}k"
+else
+  JAVAMEM="2048m"
+fi

Portable Graceful Shutdown Loop & PID Validation

  • PID Validation: Validates that .tmp/looker.pid exists before attempting to read it and kill the process.
  • POSIX Loop: Replaces the Bash-specific loop for i in {1..30} with a POSIX-compliant while loop, ensuring graceful shutdown works on Debian/Ubuntu (which use dash as /bin/sh by default).
  • Modernization: Updates cat backticks to $() syntax.
@@ -92,4 +92,8 @@
 stop() {
-    pid=`cat .tmp/looker.pid`
+    if [ ! -f .tmp/looker.pid ]; then
+        echo "Error: .tmp/looker.pid not found."
+        exit 1
+    fi
+    pid=$(cat .tmp/looker.pid)
     if [ -f .status_server_token ] && [ -x /usr/bin/curl ]; then
         state="running"
-        token=`cat .status_server_token`
+        token=$(cat .status_server_token)
         request="control/stop?token=${token}"
@@ -99,4 +103,5 @@
         fi
-        for i in {1..30}; do
+        i=1
+        while [ $i -le 30 ]; do
             timeout 20 curl -m 5 -ks ${PROTOCOL}://127.0.0.1:${LOOKERPORT}/alive > /dev/null 2>&1
             ECODE=$?
@@ -107,3 +112,4 @@
             fi
             sleep 1
+            i=$((i + 1))
         done

Add a new startup script `looker21` specifically for running Looker on JDK 21.
This script:
- Enforces JDK 21 version check.
- Adds JVM flags required for JRuby compatibility on JDK 21:
  - `--add-opens=java.base/sun.nio.ch=ALL-UNNAMED`
  - `--add-opens=java.base/java.io=ALL-UNNAMED`
  - `--add-opens=java.base/java.nio=ALL-UNNAMED`
- Removes obsolete Nashorn flags.

This allows on-premise customers to transition to JDK 21.
@mnvsngv mnvsngv requested a review from a team as a code owner July 14, 2026 20:39

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new startup script startup_scripts/looker21 to support running Looker with OpenJDK 21. The feedback highlights several shell scripting issues to improve robustness and POSIX compliance: replacing the Bash-specific brace expansion {1..30} with a POSIX-compliant while loop, using string comparison instead of -ne to avoid syntax errors when java is missing, handling potential failures of the cd command, adding a fallback for memory calculation if /proc/meminfo is unavailable, and verifying the existence of the PID file before reading it.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread startup_scripts/looker21 Outdated
Comment thread startup_scripts/looker21 Outdated
Comment thread startup_scripts/looker21 Outdated
Comment thread startup_scripts/looker21 Outdated
Comment thread startup_scripts/looker21 Outdated
…feedback

Apply suggestions from code review to improve portability and safety of the `looker21` script:
- Use string comparison for Java version check to handle empty values.
- Make directory change (`cd`) safe and quote paths.
- Make memory calculation robust with fallback and POSIX arithmetic.
- Use POSIX-compliant loop instead of Bash brace expansion `{1..30}` in `stop()`.
- Verify PID file existence before reading it in `stop()`.
@mnvsngv mnvsngv merged commit 8d141bb into looker-open-source:main Jul 14, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants