question about status behavior in tomcat init script

August Simonelli <[email protected]>
Newsgroups gmane.linux.jpackage.general
Message-ID <CAMB9GMqpjep82xxkOKtKhJAxHE4Vgs4KAipNz2dr+ofwQym7nw@mail.gmail.com>
Hi all,

A colleague at work found this one and i thought i'd ask y'all about it ...

In the tomcat6 and tomcat7 init scripts with the jpackage tomcat
packages (/etc/init.d/tomcat6) the status command does this:

/usr/bin/pgrep -d , -u ${TOMCAT_USER} -G ${TOMCAT_USER} java

However, we run multiple catalina_base's (ie 3 or 4 tomcats) per host
(set in the sysconfig file for the tomcat) and that command returns:

/usr/bin/pgrep -d , -u tomcat -G tomcat java
3339,3365,3379

The problem seems to be when you stop one of the  tomcat instances.
Stopping an instance removes the pid file ("/var/run/${NAME}.pid; as
suggested the instance's init script is a symlink:
/etc/init.d/my_instance -> /etc/init.d/tomcat6). So, once you stop
"my_instance" the pid file is removed. If you then run the status
command for that instance (ie /etc/init.d/my_instance status) the
first condition, a check for the pid file, fails and we go into the
"else":

        else
            pid="$(/usr/bin/pgrep -d , -u ${TOMCAT_USER} -G
${TOMCAT_USER} java)"
            if [ -z "$pid" ]; then
#               status ${NAME}
#               RETVAL="$?"
                echo "${NAME} is stopped"
                RETVAL="3"
            else
                echo "${NAME} (pid $pid) is running..."
                RETVAL="0"
            fi
        fi

This runs the pgrep, which returns the process list:

/usr/bin/pgrep -d , -u tomcat -G tomcat java
3365,3379

minus the stopped tomcat. However the command checks:

 if [ -z "$pid" ]; then

which will come back false (as the other tomcats running will load up
$pid) and we drop to the last else:

  else
                echo "${NAME} (pid $pid) is running..."
                RETVAL="0"

and the tomcat is reported as running.

It seems the pgrep is just not specific enough to the instance ...
shouldn't it be grep'ing or awlking for ${NAME} to ensure that the
instance it is reporting on is indeed the one specified in the the
init script used (ie /etc/init.d/my_instance)?

Apologies if we've missed something obvious ... i know "status" isn't
the most critical detail but we puppet to check the status to be sure
the tomcat is down ...

Thanks!

August
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.