Bug 1314177 - Tomcat init script reports wrong status when one instance of several is stopped
Tomcat init script reports wrong status when one instance of several is stopped
Status: CLOSED ERRATA
Product: Fedora EPEL
Classification: Fedora
Component: tomcat (Show other bugs)
el6
All Linux
unspecified Severity low
: ---
: ---
Assigned To: Coty Sutherland
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2016-03-03 02:55 EST by Rob Noble
Modified: 2016-09-02 05:22 EDT (History)
5 users (show)

See Also:
Fixed In Version: tomcat-7.0.70-2.el6
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-09-02 05:22:42 EDT
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 Rob Noble 2016-03-03 02:55:38 EST
Description of problem:
When multiple tomcat instances are created by following the instructions in comments at the top of /etc/sysconfig/tomcat, and several tomcat instances are running but one is stopped, "service <name-of-stopped-tomcat-instance> status" reports that the service is running, and lists the PIDs of the other instances.

Version-Release number of selected component (if applicable):
7.0.65-1.el6

How reproducible:
Create at least one extra tomcat instance by following the instructions at the top of /etc/sysconfig/tomcat (i.e. hard-link /etc/rc.d/init.d/tomcat to a new service name, create a matching /etc/sysconfig/<name> with its own CATALINA_BASE, ...)

Steps to Reproduce:
1. start all tomcat instances
2. stop one tomcat instance (e.g. "stopme")
3. service stopme status

Actual results:
stopme (pid 8427,9933) is running...                       [  OK  ]

Expected results:
stopme is stopped                                            [  OK  ]

Additional info:
Comment 1 Coty Sutherland 2016-03-29 12:18:26 EDT
Can you provide full steps for reproduction? I created another instance locally, but it looks like when I issue a service stop it stops all instances. In your case, it doesn't seem to stop anything so I must be doing something different.
Comment 2 Rob Noble 2016-03-30 10:16:08 EDT
Ok, here goes:

# Create a fresh Centos 6.7 VM, then as root:

yum update
yum install epel-release -y
yum install tomcat -y
mkdir /opt/stopme
cp /etc/sysconfig/tomcat /etc/sysconfig/stopme
# All vars need to be set, not just those that are being changed:
sed -i \
    -e 's,#\([A-Z_]*=.*\),\1,' \
    -e 's,CATALINA_BASE=.*,CATALINA_BASE=/opt/stopme,' \
    -e 's,CONNECTOR_PORT=.*,CONNECTOR_PORT=8081,' \
        /etc/sysconfig/stopme
# /etc/sysconfig/stopme won't work unless TOMCAT_CFG is set:
echo "TOMCAT_CFG=/etc/sysconfig/stopme" >> /etc/sysconfig/stopme
chown tomcat:tomcat /etc/sysconfig/stopme
ln /etc/rc.d/init.d/tomcat /etc/rc.d/init.d/stopme
cp -a /usr/share/tomcat/bin /opt/stopme/
cp -a /usr/share/tomcat/lib /opt/stopme/
mkdir /opt/stopme/conf
mkdir /opt/stopme/logs
cp -a /usr/share/tomcat/conf/* /opt/stopme/conf/
sed -i \
    -e 's,port="8005",port="8006",' \
    -e 's,port="8080",port="8081",' \
    -e 's,port="8009",port="8010",' \
        /opt/stopme/conf/server.xml
chown -R tomcat:tomcat /opt/stopme
service tomcat start
service stopme start

Note:
$ service stopme status
stopme (pid 28202,28292) is running...                     [  OK  ]

It's reporting the pids of both instances, when I asked for the status of "stopme" only.

And:
$ service stopme stop
Stopping stopme: 
$ service stopme status
stopme (pid 28202) is running...                           [  OK  ]

I.e. after stopping the "stopme" instance, and asking for the status of the "stopme" instance, it reports that it is running, and displays the pid of the main tomcat instance.

The problem is that to find the pid of the instance it just does this:

pid="$(/usr/bin/pgrep -d , -u ${TOMCAT_USER} -G ${TOMCAT_USER} java)"

which catches all tomcat instances (and any other java process being run by the tomcat user).

I'm not sure if this is valid, but changing it to this seems to fix the problem:

pid="$(/usr/bin/pgrep -f -d , -u ${TOMCAT_USER} -G ${TOMCAT_USER} ${CATALINA_BASE})"

(Note there are two places in the init script where this is run).

HTH,
Rob.
Comment 3 Coty Sutherland 2016-03-30 13:28:07 EDT
When I run the commands above, status gives me on RHEL6:

[root@fed-epel6 ~]# service stopme status
PID file exists, but process is not running                [WARNING]

Testing on CentOS works as you expressed though. Walking through your steps, it looks like you didn't specify a separate PID file. Was there some reason you didn't do so? Adding the following resolves the multiple PID listing in status:

sed -i -e 's,CATALINA_PID=.*,CATALINA_PID="/var/run/stopme.pid",' /etc/sysconfig/stopme

but it still doesn't correctly stop an instance. I modified my script to a slight variation of your suggestion (to match on more of the command in case there are other processes running with the base path in them) to:

pid="$(/usr/bin/pgrep -f -d , -u ${TOMCAT_USER} -G ${TOMCAT_USER} Dcatalina.base=${CATALINA_BASE})"

and that looks to work.

What do you think about this solution?

https://github.com/csutherl/fedora-tomcat/commit/19cdc42
Comment 4 Rob Noble 2016-05-10 04:48:53 EDT
Sincere apologies for the slow reply (a bunch of "stuff" took over my time...).  

In fact I have been setting CATALINA_PID for each of my instances - not sure why I didn't include that when I created the fresh test VM.

Your solution looks fine, thank you.

Rob.
Comment 5 Coty Sutherland 2016-08-05 09:59:02 EDT
https://pkgs.fedoraproject.org/cgit/rpms/tomcat.git/commit/?h=el6&id=8e804f0
https://pkgs.fedoraproject.org/cgit/rpms/tomcat.git/commit/?h=el6&id=56cc1de

This is a little different than the original proposal, but this is how I fixed the issue in the JBoss Web Server product, so I know it works.
Comment 6 Fedora Update System 2016-08-05 16:10:54 EDT
tomcat-7.0.70-2.el6 has been submitted as an update to Fedora EPEL 6. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-3ff1f4485b
Comment 7 Fedora Update System 2016-08-08 22:18:01 EDT
tomcat-7.0.70-2.el6 has been pushed to the Fedora EPEL 6 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-3ff1f4485b
Comment 8 Fedora Update System 2016-09-01 12:20:15 EDT
tomcat-7.0.70-2.el6 has been pushed to the Fedora EPEL 6 stable repository. If problems still persist, please make note of it in this bug report.
Comment 9 Fedora Update System 2016-09-02 05:22:05 EDT
tomcat-7.0.70-2.el6 has been pushed to the Fedora EPEL 6 stable repository. If problems still persist, please make note of it in this bug report.

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