What this module does #
Apache Tomcat is upgraded, in a stock install, by unpacking a new tarball on top of the old one or by rebuilding the machine. Both approaches are error-prone: the first mixes versions, the second loses the deployed apps.
The tomcat module solves that: it installs each version under its own /opt/tomcat/apache-tomcat-X.Y.Z, versioned and immutable, and flips a current symlink to switch between them. Your webapps/, conf/, lib/ and /var/log/tomcat live in CATALINA_BASE (/var/lib/tomcat) and are never touched by upgrade or rollback. Every install verifies sha512 and PGP signature against the branch KEYS from downloads.apache.org, and the mandatory Tomcat↔Java matrix stops you from running a version on the wrong JVM.
Every mutating command needs root (use sudo). Upgrade downtime is seconds — the service is stopped, the symlink flipped and started back up — but the cache in memory is lost on each restart. Cross-major jumps (10→11) are blocked by default because of javax→jakarta; use --allow-major only after you have tested your apps.
Quick guide #
Pick what you want to do. Every recipe comes with the command already written — just copy it and hit Copy.
1
Check the service status
See the active version, CATALINA_BASE, Java and the rollback target at a glance.
Connect to your instance over SSH with the ubuntu user.
Ask for the status:
$ sudo imaxe tomcat statusFor a dashboard or a script, add --json:
$ sudo imaxe tomcat status --json2
List installed versions
See which versions are on disk and which one is active (*).
*).Local versions:
$ sudo imaxe tomcat listLast 10 releases of a branch upstream:
$ sudo imaxe tomcat list --remote 10.13
Upgrade in place
Install the newest release of the active branch, atomic flip, automatic rollback on failure.
Preview without touching anything:
$ sudo imaxe tomcat upgrade --dry-runApply it (downtime measured in seconds):
$ sudo imaxe tomcat upgradePin the target and clean out work/+temp/:
$ sudo imaxe tomcat upgrade --to 10.1.30 --clear-work30 means: the new version stayed on disk for you to inspect, and Tomcat is running on the old one.4
Roll back to the previous version
Flip current back to the previous entry in the history.
current back to the previous entry in the history.$ sudo imaxe tomcat rollback20 means there is no previous version to roll back to. If you want to jump to a specific installed version, use switch <X.Y.Z>.5
Run the doctor
Full healthcheck: service, HTTP, matrix, layout, NGINX.
$ sudo imaxe tomcat doctorGET http://127.0.0.1:8080/, the Tomcat↔Java pair, layout permissions, the logs symlink, AJP absent in server.xml, disk space and NGINX on 80/443.Synopsis #
imaxe tomcat <subcommand> [flags]Every subcommand needs root. Add --json to status, list or doctor for machine-readable output.
Subcommands #
| Subcommand | What it does | Relevant flags |
|---|---|---|
| status | Active version, CATALINA_BASE, Java, ports, rollback target. | --json |
| list | Installed versions (marks the active one with *); --remote lists upstream releases of a branch. | --json --remote |
| install | Installs a version. Verifies sha512 and PGP signature, applies the matrix and installs Temurin if needed. | --java --force-java |
| upgrade | Atomic upgrade with healthcheck and automatic rollback on failure. | --to --keep --clear-work --dry-run --allow-major |
| switch | Flips current to an already-installed version. | — |
| rollback | Goes back to the previous entry in the history. | — |
| doctor | Full healthcheck: unit, HTTP, matrix, layout, NGINX. | --json |
Arguments and flags #
| Flag | Type | Default | Description |
|---|---|---|---|
| --to | string | latest-<branch> | In upgrade: target version (X.Y.Z, latest-9, latest-10.1, latest-11). |
| --java | int | matrix | In install: Temurin version to install; without it, the matrix default. |
| --force-java | bool | false | Allows a Tomcat↔Java pair outside the matrix. Logged to the state file. |
| --keep | int | 2 | How many previous versions to keep after a prune. |
| --clear-work | bool | false | Empties work/ and temp/ after the flip. |
| --dry-run | bool | false | Prints the plan; does not touch anything. |
| --allow-major | bool | false | Allows cross-major jumps (10→11, 11→12). Test your apps first: javax→jakarta. |
| --remote | string | — | In list: shows the latest releases of the branch on archive.apache.org. |
| --json | bool | false | Emits the result as structured JSON on stdout. |
Files and paths #
| Path | Contents |
|---|---|
| /etc/imaxe/tomcat.yml | Module configuration: branch, mirrors, matrix, healthcheck. |
| /opt/tomcat/apache-tomcat-X.Y.Z | Versioned and immutable CATALINA_HOME. One directory per installed release. |
| /opt/tomcat/current | Symlink pointing at the active release. Every upgrade/rollback flips it atomically. |
| /var/lib/tomcat | CATALINA_BASE: conf/, webapps/, lib/, work/, temp/. Untouched by upgrade/rollback. |
| /var/log/tomcat | Logs (symlinked from /var/lib/tomcat/logs). Own logrotate. catalina.out also captured by journald. |
| /var/lib/imaxe/state/tomcat/state.json | State: active version, history, installed Java, matrix escapes. |
| /var/lib/imaxe/cache/tomcat/keys-<major>.gpg | Cached branch KEYS ring used by gpgv to verify signatures. |
Exit codes and logs #
Every run returns a code you can check with echo $?:
--allow-major after testing your apps.Follow the service live while you work:
$ sudo systemctl status tomcat
$ sudo journalctl -u tomcat -fTroubleshooting #
| Symptom | Likely cause | Fix |
|---|---|---|
Exit 2 on install | sha512 or PGP verification failed. | Retry: it may be a corrupted mirror. If it happens twice, check keys-<major>.gpg and the target URL in tomcat.yml. |
Exit 25 on upgrade | Cross-major jump blocked (10→11, javax→jakarta). | Test your apps and, if OK, re-run with --allow-major. |
Exit 30 after upgrade | The healthcheck failed after the symlink flip; module rolled back automatically. | Check journalctl -u tomcat. The new version stays on disk for you to inspect; delete it with rm -rf /opt/tomcat/apache-tomcat-X.Y.Z. |
| Manager returns 403/404 via the public URL | Correct: it only listens on loopback. | Reach it through an SSH tunnel (ssh -L 8080:127.0.0.1:8080) and open http://127.0.0.1:8080/manager/html. |
| NGINX returns 502 | Tomcat is not up. | sudo systemctl status tomcat, then imaxe tomcat doctor. |
هل واجهتك مشكلة مع وحدة Tomcat؟
راسلنا مرفقًا مخرجات «imaxe <module> status --json» وسنرد عليك بسرعة.