2

We have tomcat6 running in two different environments, both running CentOS 6.6 and OpenJDK 1.7. In one environment, I'm not able to stop tomcat6 when issuing

service tomcat6 stop

In the environment that this is failing, the only difference is that there are some additional options:

-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=**8081**
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote=true
-Djava.rmi.server.hostname=172.19.13.211

When stopping, the following errors are recorded in catalina.out:

OpenJDK 64-Bit Server VM warning: Failed to reserve shared memory (errno = 1).
OpenJDK 64-Bit Server VM warning: Failed to reserve shared memory (errno = 1).
OpenJDK 64-Bit Server VM warning: Failed to reserve shared memory (errno = 1).
Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: **8081**; nested exception is: 
        java.net.BindException: Address already in use

It looks like the jmx port is what is causing this issue, but without removing it altogether, is there a way to get tomcat6 to stop gracefully?

UPDATE 1

The link mentioned in my comment led me to a blog post that I followed. I created the /usr/share/tomcat6/bin/setenv.sh file, and made it readable with the following contents:

export CATALINA_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8081 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote=true -Djava.rmi.server.hostname=172.19.13.211"

However, when starting tomcat6 up, the jmx options are not being included. Any suggestions?

2
  • sort out the jmx port asin change the 8081 to something else
    – ericnyamu
    Nov 10, 2015 at 17:21
  • A bit more searching yielded another thread. Will update accordingly.
    – vmoralito
    Nov 10, 2015 at 17:22

1 Answer 1

0

Here's what worked for me:

Using some information from this page I added the following to the tomcat6 startup script (which in my case was /usr/sbin/tomcat6):

if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
  . "$CATALINA_BASE/bin/setenv.sh"
elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
  . "$CATALINA_HOME/bin/setenv.sh"
fi

The final contents of my /usr/share/tomcat6/bin/setenv.sh file:

#!/bin/sh
export CATALINA_OPTS="-Dcom.sun.management.jmxremote.authenticate=false \
                      -Dcom.sun.management.jmxremote.port=8081 \
                      -Dcom.sun.management.jmxremote.ssl=false \
                      -Dcom.sun.management.jmxremote=true \ 
                      -Djava.rmi.server.hostname=172.19.13.211"

Now I can start tomcat6 successfully with the jmx options:

[root@hrndvsoi-dev1-ucsync01 tomcat6]# service tomcat6 start
Starting tomcat6:                                          [  OK  ]

[root@hrndvsoi-dev1-ucsync01 tomcat6]# ps -ef | grep tomc | grep -v grep | sed -e 's/ /\n/g' | grep -e jmx -e rmi
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=8081
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote=true
-Djava.rmi.server.hostname=172.19.13.211

And I can stop tomcat6 without any errors:

[root@hrndvsoi-dev1-ucsync01 tomcat6]# service tomcat6 stop
Stopping tomcat6:                                          [  OK  ]

Hope this helps someone else.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .