Bug 1372789

Summary: init script status command gives incorrect result
Product: [Fedora] Fedora EPEL Reporter: Ken Geis <geis.ken>
Component: tomcatAssignee: Coty Sutherland <csutherl>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: el6CC: alee, coolsvap, csutherl, geis.ken, ivan.afonichev, trick
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: tomcat-7.0.75-1.el6 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-03-22 14:47:37 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Attachments:
Description Flags
patch proposal for testing
none
correct patch none

Description Ken Geis 2016-09-02 17:03:39 UTC
Description of problem:
I am running a service with a different NAME than tomcat. When I ask for its status, it says that it's not running.

Version-Release number of selected component (if applicable):
7.0.70-2.el6

How reproducible:
I was able to reproduce it simply as below.

Steps to Reproduce:
1. create additional Tomcat service by linking foo to tomcat in /etc/init.d
2. create a simple Catalina base in /tmp/bar
3. in /etc/sysconfig/foo set
    CATALINA_BASE=/tmp/bar
    CATALINA_TMPDIR=/tmp/bar/temp
    CATALINA_PID=/var/run/foo.pid
4. service foo start
5. service foo status

Actual results:
<NAME> (pid <pid>) is running...                        [  OK  ]
<NAME> lockfile exists but process is not running       [FAILED]

Expected results:
<NAME> (pid <pid>) is running...                        [  OK  ]


Additional info:
/etc/init.d/tomcat tries to get the PID by
            pid="$(/usr/bin/pgrep -d , -u ${TOMCAT_USER} -G ${TOMCAT_USER} -f "${NAME}[ $]")"
This does not work here because ${NAME} does not appear anywhere in the command line. Perhaps it would if $CATALINA_BASE contained $NAME.

Comment 1 Ken Geis 2016-09-02 17:07:04 UTC
I am able to work around this by changing the test to

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

Comment 2 Coty Sutherland 2016-09-02 17:41:42 UTC
Thanks for the report, Ken. I made a bad assumption that $NAME would always be available, but it isn't (as you said). I think $CATALINA_BASE will work fine (I tested it previously), so I'll try and switch over to that method soon.

Comment 3 Coty Sutherland 2017-02-10 20:32:19 UTC
I tested this a bit more and it seems that you need to specify which property you're looking for instead of just "${CATALINA_BASE}[ $]", otherwise you'll get false positives when you have the same CATALINA_HOME as some other service.

I'm attaching a patch shortly, can you test to verify I didn't miss something?

Comment 4 Coty Sutherland 2017-02-10 20:33:13 UTC
Created attachment 1249138 [details]
patch proposal for testing

Here's what I think works best.

Comment 5 Coty Sutherland 2017-02-10 20:39:00 UTC
Created attachment 1249139 [details]
correct patch

That other patch was from the wrong version :(

Comment 6 Ken Geis 2017-02-10 22:09:26 UTC
This patch works for me. It would be more correct to escape the . in the pattern.

Comment 8 Fedora Update System 2017-02-17 20:29:33 UTC
tomcat-7.0.75-1.el6 has been submitted as an update to Fedora EPEL 6. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2017-c3b112eb9e

Comment 9 Fedora Update System 2017-02-18 19:16:40 UTC
tomcat-7.0.75-1.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-2017-c3b112eb9e

Comment 10 Fedora Update System 2017-03-22 14:47:37 UTC
tomcat-7.0.75-1.el6 has been pushed to the Fedora EPEL 6 stable repository. If problems still persist, please make note of it in this bug report.