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:
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.
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.
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
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.
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.
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
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
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.