12

I started tomcat 7 using,

cd /opt/tomcat7/bin    
$/opt/tomcat7/bin ./startup.sh

It shows process running

root     23206  130  3.4 1323956 572880 pts/2  Sl   07:58   1:05 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Dspring.profiles.active=mongo1,maxListenersAllowed -DST_SERVER=mongo1 -Djava.endorsed.dirs=/opt/tomcat7/endorsed -classpath /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat7 -Dcatalina.home=/opt/tomcat7 -Djava.io.tmpdir=/opt/tomcat7/temp org.apache.catalina.startup.Bootstrap start

If I shutdown it using

$/opt/tomcat7/bin ./shutdown.sh

It gives this message

Using CATALINA_BASE:   /opt/tomcat7
Using CATALINA_HOME:   /opt/tomcat7
Using CATALINA_TMPDIR: /opt/tomcat7/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar

but if I check the above process, it still shows it running. Tomcat doesn't shut down. I tried it using root user as well but still no success.

Manully I can kill the process but I want to create deploy script so want to do it using shutdown.sh and startup.sh

Same happens if I try using

/opt/tomcat7/bin/catalina.sh start
/opt/tomcat7/bin/catalina.sh stop

Log

Jul 23, 2014 8:26:17 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/i386:/lib:/usr/lib
Jul 23, 2014 8:26:18 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8081"]
Jul 23, 2014 8:26:18 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 361 ms
Jul 23, 2014 8:26:18 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jul 23, 2014 8:26:18 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.53
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/docs
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/manager
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/ROOT
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/examples
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/host-manager
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/target
Jul 23, 2014 8:26:18 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8081"]
Jul 23, 2014 8:26:18 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 862 ms
Jul 23, 2014 8:26:42 AM org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8081"]
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
Jul 23, 2014 8:26:42 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8081"]
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8081"]
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-8009"]
DavidPostill
  • 7,734
  • 9
  • 41
  • 60
vishal
  • 3,993
  • 14
  • 59
  • 102
  • Which tomcat version exactly is it? Did you already deploy anything, or is this just a plain vanilla installation from the download package? And, which JRE version are you using (`/usr/bin/java -version`)? – Andreas Fester Jul 23 '14 at 07:14
  • Possible duplicate of [this](http://stackoverflow.com/questions/9971876/tomcat-doesnt-stop-how-can-i-debug-this) – Mustafa sabir Jul 23 '14 at 07:21
  • Can you post the logs for the shutdown hook ? – Saif Asif Jul 23 '14 at 07:25

4 Answers4

14

You can force the shutdown by PID.

Edit

..tomcat/bin/catalina.sh

and set the

CATALINA_PID=path

variable to a local path.

CATALINA_PID

(Optional) Path of the file which should contains the pid of the catalina startup java process, when start (fork) is used

then you can shutdown Tomcat with -force flag

../tomcat/bin/shutdown.sh -force

If the script can not stop Tomcat normally will use a kill to stop the process by PID.

Update:

According to Joshua Taylor comment, the recommended way to store additional variables for running tomcat is the setenv.* script.

Take a look at (3.4) Using the "setenv" script (optional, recommended) section in the tomcat running docs

https://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt

vzamanillo
  • 9,905
  • 1
  • 36
  • 56
  • 3
    Note that catalina.bat says: **Do not set the variables in this script. Instead put them into a script setenv.sh in CATALINA_BASE/bin to keep your customizations separate.**. CATALINA_PID should be set there instead. – Joshua Taylor Oct 09 '15 at 20:46
1

If you are in windows, and using the portable tomcat, you can use the nircmd program tool, and close by title console window, instead of stopping by PID. When you have downloaded this tool, just do:

nircmd.exe win close title "Tomcat"
Alberto Perez
  • 1,019
  • 15
  • 17
1

I once had the misfortune of a page running infinite redirect loops due to a faulty authentication mechanism.

It eventually slowed down the entire server, but also made it impossible for me to shut it down gracefully. In the end I had to employ brute force like vzamanillo describes.

The point being that something fishy might be running within your server's processes that won't finish properly.

JohannSig
  • 131
  • 2
  • 8
0

Is you shutdown port set? (in /etc/tomcat9/conf/server.xml )

<Server  port="9005"  shutdown="SHUTDOWN">
  • 2
    The log says _"INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance."_, therefore the shutdown port is configured. – Piotr P. Karwasz Jul 06 '21 at 20:02
  • On linux (and probably windows), the problem might then be the logs. If the user running the instance does not have enough rights ont the logs in /var/log/tomcat, it makes the instance hang (i guess trying to roll logs etc.). Running the instance as the right user might help spot the problem: /bin/su $TOMCAT_USER -s /bin/bash -c $CATALINA_HOME/bin/shutdown.sh –  Jul 07 '21 at 16:12