Tomcat JDK Update

These scripts move m-Power's Tomcat onto the latest Amazon Corretto build of the same Java major version it runs today (for example Corretto 21.0.9 → 21.0.13). They will never move you to a new major version (21 → 25).

The script detects the JDK the running Tomcat uses, asks corretto.aws for the newest build of that major version, downloads it (checksum-verified), stops Tomcat, switches it to the new JDK and restarts it. If Tomcat fails to start on the new JDK, it is automatically switched back to the previous one. If Tomcat is already on the latest build, the script exits without changing anything.

Only Tomcats whose home folder is inside an m-power folder are updated (e.g. C:\Program Files\mrc\development\m-power\tomcat, /mrc/production/m-power/tomcat). Any other Tomcat on the machine is listed as skipped and left alone.

Windows

Easiest: double-click update-tomcat-jdk.bat. It asks for administrator rights (accept the UAC prompt), finds every m-Power Tomcat service (TC10DEV, TC10PROD, ...), shows what it will do and asks before stopping anything.

update-tomcat-jdk.bat /check              <- report only, change nothing
update-tomcat-jdk.bat /service:TC10DEV    <- only this service
update-tomcat-jdk.bat /yes                <- no prompt, no pause (scheduled / unattended runs)
StepWhat happens
DetectThe jvm.dll the running Tomcat service has loaded (or its configured JVM if stopped); the version comes from that JDK's release file.
DownloadThe Corretto MSI, checked against Amazon's published SHA-256 and its Amazon code signature.
InstallTomcat is stopped, the MSI is installed silently into C:\Program Files\Amazon Corretto\.
SwitchThe service's JVM setting is pointed at the new jvm.dll; start_tomcat.bat, end_tomcat.bat and update-webxml.bat in the m-power folder get the new JDK path (backups kept as .bak-<date>).

Log and downloads: %ProgramData%\m-Power\jdk-update.

Linux

Run as root:

chmod +x update-tomcat-jdk.sh     # first time only
./update-tomcat-jdk.sh -n          # report only, change nothing
./update-tomcat-jdk.sh
ArgumentMeaning
-nCheck only: report what would change, change nothing.
-yDo not ask for confirmation (unattended runs).
-c (catalina home)A Tomcat to update; repeat for several. Default: every running Tomcat, plus /mrc/development/m-power/tomcat, /mrc/production/m-power/tomcat and the tomcat folder next to this script's folder.

m-Power does not ship a JDK on Linux, so the script installs Corretto from Amazon's tarball into /opt/amazon-corretto/ and points each Tomcat at it with a JAVA_HOME block at the end of <tomcat>/bin/setenv.sh (backup kept as setenv.sh.bak-<date>). The system java, alternatives and any installed packages are not changed. Tomcat is stopped and started through its systemd unit if one references the Tomcat folder, otherwise with shutdown.sh/startup.sh as the folder's owner. The script checks the restarted JVM really runs from the new JDK; if the start-up ignores setenv.sh (for example a unit that launches java directly), it switches back and says so.

Log: /tmp/tomcat-jdk-update-<date>.log.

Good to know