Bug 63063

Summary: 8.5.37 does not longer start because of error in catalina.sh start section with new redirect to $catalina_out_command eval code code block
Product: Tomcat 8 Reporter: Patrik S. <patrik.sch>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED DUPLICATE    
Severity: major CC: lopaka
Priority: P2    
Version: 8.5.x-trunk   
Target Milestone: ----   
Hardware: PC   
OS: Linux   

Description Patrik S. 2019-01-07 13:38:18 UTC
In relation to ticket https://bz.apache.org/bugzilla/show_bug.cgi?id=53930
since tomcat 8.5.36 the catalina.sh start section was changed to handle the stdout & stderr redirect into $CATALINA_OUT in another way.

But with 8.5.37 release I was not longer able to start the tomcat by using systemd. On the other hand I was able to start it manually by calling bin/startup.sh. This was strange....

At the end I hopyfully found the simple fault in catalina.sh start section.
During the rebuild of the eval .... code blocks in lines 470 ++ and 482 ++ there is a typo.

Line 479 and 489 contains both that code:
 2\>\&1 \& echo \$! \>\"$catalina_pid_file\" \; \} $catalina_out_command "&"

but since the redirect "2\>\&1" finishes the command call, the next "\&" has to be a:
1. "\;" to delimiter the follow up command "echo \$!"
2. or I belive it should be a double ampersand "\&\&" to combine both shell commands

After I changed both lines into:
for case 1: 2\>\&1 \; echo \$! \>\"$catalina_pid_file\" \; \} $catalina_out_command "&"

for case 2: 2\>\&1 \&\& echo \$! \>\"$catalina_pid_file\" \; \} $catalina_out_command "&"


it works again for me with both variants.
Comment 1 Igal Sapir 2019-01-08 05:37:58 UTC
Possibly related to BZ-63041
Comment 2 Patrik S. 2019-01-08 07:48:28 UTC
Yes, it's the same issue as in tomcat 9.0 with BZ-63041.
"Could not contact [localhost:[8005]]. Tomcat may not be running." is the only error shown in journalctl -xe

Adding "set -x" to catalina.sh shows following output after trying to start the service:

output of journalctl -xe
   [.....]
   Jan 07 13:19:58 machinehostname startup.sh[26562]: + eval '{' '"/opt/java/bin/java"' '"-Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties"' -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.proto
   Jan 07 13:19:58 machinehostname startup.sh[26562]: + echo 'Tomcat started.'
   Jan 07 13:19:58 machinehostname startup.sh[26562]: Tomcat started.

startup.sh script finished, but shutdown is called directly afterwards:
   Jan 07 13:19:58 machinehostname shutdown.sh[26577]: + os400=false
   .......
   Jan 07 13:19:58 machinehostname shutdown.sh[26577]: Jan 07, 2019 1:19:58 PM org.apache.catalina.startup.Catalina stopServer
   Jan 07 13:19:58 machinehostname shutdown.sh[26577]: SEVERE: Could not contact [localhost:[8005]]. Tomcat may not be running.
   Jan 07 13:19:58 machinehostname shutdown.sh[26577]: Jan 07, 2019 1:19:58 PM org.apache.catalina.startup.Catalina stopServer
   Jan 07 13:19:58 machinehostname shutdown.sh[26577]: SEVERE: Catalina.stop:
   Jan 07 13:19:58 machinehostname shutdown.sh[26577]: java.net.ConnectException: Connection refused (Connection refused)
Comment 3 Mark Thomas 2019-01-09 09:02:44 UTC

*** This bug has been marked as a duplicate of bug 63041 ***