Bug 1304220 - Tomcat init script does not respect setting of CATALINA_PID in /etc/sysconfig/tomcat
Tomcat init script does not respect setting of CATALINA_PID in /etc/sysconfig...
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: tomcat (Show other bugs)
7.2
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: Coty Sutherland
tomcat-qe
:
Depends On: 1104708
Blocks: 1298191
  Show dependency treegraph
 
Reported: 2016-02-02 22:40 EST by Coty Sutherland
Modified: 2016-02-02 22:49 EST (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1104708
Environment:
Last Closed: 2016-02-02 22:49:36 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Coty Sutherland 2016-02-02 22:40:21 EST
+++ This bug was initially created as a clone of Bug #1104708 +++

Description of problem:
No matter what CATALINA_PID is set to in /etc/sysconfig/${NAME}, /etc/init.d/tomcat assumes the pid file is at /var/run/${NAME}.pid

Version-Release number of selected component (if applicable):
7.0.33-4

How reproducible:
Set CATALINA_PID to something other name /var/run/${NAME}.pid in /etc/sysconfig/${NAME}

Steps to Reproduce:
1. echo 'CATALINA_PID=/var/run/whatsmyname.pid' >> /etc/sysconfig/tomcat
2. service tomcat start

Actual results:
CATALINA_PID=/var/run/tomcat.pid

Expected results:
CATALINA_PID=/var/run/whatsmyname.pid

Additional info:
This ends up a problems because the Tomcat init script sets the ownership on CATALINA_PID to TOMCAT_USER:TOMCAT_GROUP so Tomcat can write to the file, but this will fail when CATALINA_PID is set to something other than /var/run/${NAME}.pid

--- Additional comment from Nico Kadel-Garcia on 2014-12-03 10:15:37 EST ---

The patch for this is below.

diff -ur tomcat-7.0.33-4.el6.pid/etc/init.d/tomcat tomcat-7.0.33-4.el6/etc/init.d/tomcat
--- tomcat-7.0.33-4.el6.pid/etc/init.d/tomcat   2014-12-03 10:12:51.689838620 -0500
+++ tomcat-7.0.33-4.el6/etc/init.d/tomcat       2014-12-03 10:10:49.812736936 -0500
@@ -69,6 +69,8 @@
 # Define the tomcat log file
 TOMCAT_LOG="${TOMCAT_LOG:-${CATALINA_HOME}/logs/${NAME}-initd.log}"

+# Define the tomcat pid file
+CATALINA_PID="${CATALINA_PID:-/var/run/${NAME}.pid}"

 RETVAL="0"

@@ -162,7 +164,6 @@
         fi
     fi
     # fix permissions on the log and pid files
-    export CATALINA_PID="/var/run/${NAME}.pid"
     touch $CATALINA_PID 2>&1 || RETVAL="4"
     if [ "$RETVAL" -eq "0" -a "$?" -eq "0" ]; then
       chown ${TOMCAT_USER}:${TOMCAT_USER} $CATALINA_PID
@@ -210,8 +211,8 @@
       fi
       if [ "$RETVAL" -eq "0" ]; then
          count="0"
-         if [ -s "/var/run/${NAME}.pid" ]; then
-            read kpid < /var/run/${NAME}.pid
+         if [ -s "$CATALINA_PID" ]; then
+            read kpid < $CATALINA_PID
             until [ "$(ps --pid $kpid | grep -c $kpid)" -eq "0" ] || \
                       [ "$count" -gt "$SHUTDOWN_WAIT" ]; do
                     if [ "$SHUTDOWN_VERBOSE" = "true" ]; then
@@ -228,7 +229,7 @@
                 fi
                 log_success_msg
             fi
-            rm -f /var/lock/subsys/${NAME} /var/run/${NAME}.pid
+            rm -f /var/lock/subsys/${NAME} $CATALINA_PID
         else
             log_failure_msg
             RETVAL="4"
@@ -262,7 +263,7 @@
         start
         ;;
     condrestart|try-restart)
-        if [ -s "/var/run/${NAME}.pid" ]; then
+        if [ -s "$CATALINA_PID" ]; then
             stop
             start
         fi
@@ -271,14 +272,14 @@
         RETVAL="3"
         ;;
     force-reload)
-        if [ -s "/var/run/${NAME}.pid" ]; then
+        if [ -s "$CATALINA_PID" ]; then
             stop
             start
         fi
         ;;
     status)
-        if [ -s "/var/run/${NAME}.pid" ]; then
-            read kpid < /var/run/${NAME}.pid
+        if [ -s "$CATALINA_PID" ]; then
+            read kpid < $CATALINA_PID
             if [ -d "/proc/${kpid}" ]; then
                 log_success_msg "${NAME} (pid ${kpid}) is running..."
                 RETVAL="0"

--- Additional comment from Coty Sutherland on 2016-02-02 22:38:39 EST ---

https://github.com/csutherl/fedora-tomcat/commit/017ab53

There was one missing /var/run/${NAME}.pid usage in the above patch, but other than that (which I added in the above commit) it looks good.
Comment 1 Coty Sutherland 2016-02-02 22:49:36 EST
Oops...just realized that RHEL 7 tomcat now uses systemd instead of sysV. Closing this because it doesn't apply. I was looking at the dist-git repo; I need to clean up those unused files.

Note You need to log in before you can comment on or make changes to this bug.