Bug 62607 - Catalina exits with status code 0 when the configuration is invalid
Summary: Catalina exits with status code 0 when the configuration is invalid
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 9.0.10
Hardware: All All
: P2 minor (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-08 13:21 UTC by Emmanuel Bourg
Modified: 2018-08-09 14:30 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Emmanuel Bourg 2018-08-08 13:21:07 UTC
With a malformed server.xml file, "catalina.sh confitest" reports the error and exits with the status code 1. But with "catalina.sh run" the status code is 0 (SUCCESS). This confuses daemon management systems like systemd which might not report the error properly, or attempt to restart the server repeatedly.

Here is a suggested fix:

--- a/java/org/apache/catalina/startup/Bootstrap.java
+++ b/java/org/apache/catalina/startup/Bootstrap.java
@@ -489,6 +489,10 @@
             } else if (command.equals("start")) {
                 daemon.setAwait(true);
                 daemon.load(args);
+                if (null == daemon.getServer()) {
+                    log.fatal("Cannot start server. Server instance is not configured.");
+                    System.exit(1);
+                }
                 daemon.start();
             } else if (command.equals("stop")) {
                 daemon.stopServer(args);
Comment 1 Mark Thomas 2018-08-09 14:14:40 UTC
Fixed in:
- trunk for 9.0.11 onwards
- 8.5.x for 8.5.33 onwards
- 7.0.x for 7.0.91 onwards
Comment 2 Emmanuel Bourg 2018-08-09 14:30:26 UTC
Thank you Mark, I could have committed it though ;)