'How to SHUTDOWN Tomcat in Ubuntu?

I tried to shutdown tomcat as shown below, but tomcat still seems to be running (http://localhost:8080/)

vandegraff@vandegraff-laptop:~$ /usr/share/tomcat6/bin/shutdown.sh 
Using CATALINA_BASE:   /usr/share/tomcat6
Using CATALINA_HOME:   /usr/share/tomcat6
Using CATALINA_TMPDIR: /usr/share/tomcat6/temp
Using JRE_HOME:       /usr
1 Nov, 2010 11:41:40 PM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop: 
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:422)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:337)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)

Why is that?


Update1 for @hvgotcodes:

Output of ps -ax | grep java

1597 ? Ss 0:00 /usr/bin/jsvc -user tomcat6 -cp /usr/share/java/commons-daemon.jar:/usr/share/tomcat6/bin/bootstrap.jar -outfile SYSLOG -errfile SYSLOG -pidfile /var/run/tomcat6.pid -Djava.awt.headless=true -Xmx128M -Djava.endorsed.dirs=/usr/share/tomcat6/endorsed -Dcatalina.base=/var/lib/tomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.io.tmpdir=/tmp/tomcat6-temp -Djava.security.manager -Djava.security.policy=/var/lib/tomcat6/work/catalina.policy -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/var/lib/tomcat6/conf/logging.properties org.apache.catalina.startup.Bootstrap

1598 ? S 0:00 /usr/bin/jsvc -user tomcat6 -cp /usr/share/java/commons-daemon.jar:/usr/share/tomcat6/bin/bootstrap.jar -outfile SYSLOG -errfile SYSLOG -pidfile /var/run/tomcat6.pid -Djava.awt.headless=true -Xmx128M -Djava.endorsed.dirs=/usr/share/tomcat6/endorsed -Dcatalina.base=/var/lib/tomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.io.tmpdir=/tmp/tomcat6-temp -Djava.security.manager -Djava.security.policy=/var/lib/tomcat6/work/catalina.policy -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/var/lib/tomcat6/conf/logging.properties org.apache.catalina.startup.Bootstrap

1599 ? Sl 0:20 /usr/bin/jsvc -user tomcat6 -cp /usr/share/java/commons-daemon.jar:/usr/share/tomcat6/bin/bootstrap.jar -outfile SYSLOG -errfile SYSLOG -pidfile /var/run/tomcat6.pid -Djava.awt.headless=true -Xmx128M -Djava.endorsed.dirs=/usr/share/tomcat6/endorsed -Dcatalina.base=/var/lib/tomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.io.tmpdir=/tmp/tomcat6-temp -Djava.security.manager -Djava.security.policy=/var/lib/tomcat6/work/catalina.policy -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/var/lib/tomcat6/conf/logging.properties org.apache.catalina.startup.Bootstrap

Should all these 3 processes - 1597, 1598, 1599 - be killed?



Solution 1:[1]

Van, in your case where tomcat won't shutdown normally, i would use

ps ax | grep java

to find the java process number. If that command returns something, then run

sudo kill -9 pid

where pid is the process number. The -9 option means 'just kill it', and normally you don't need this sort of thing, but since in your situation the process won't stop normally, you need it.

The output of the first command should look like

38678 s002  U      0:02.62 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java -Djava.util.logging.config.file=/usr/share/apache-tomcat-6.0.26/conf/logging.properties -Xms2048m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=512m -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8086 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=xxxx -Djava.endorsed.dirs=/usr/share/apache-tomcat-6.0.26/endorsed -classpath /usr/share/apache-tomcat-6.0.26/bin/bootstrap.jar -Dcatalina.base=/usr/share/apache-tomcat-6.0.26 -Dcatalina.home=/usr/share/apache-tomcat-6.0.26 -Djava.io.tmpdir=/usr/share/apache-tomcat-6.0.26/temp org.apache.catalina.startup.Bootstrap start

38678 is the process number. Be aware that there might be other java processes running that you might not want to kill. Also, this output is from a mac, so on ubuntu will look slightly different.

Solution 2:[2]

Try

/etc/init.d/tomcat stop

(maybe you have to write something after tomcat, just press tab one time)

Edit: And you also need to do it as root.

Solution 3:[3]

Try using this command : (this will stop tomcat servlet this really helps)

sudo service tomcat7 stop

or

sudo tomcat7 restart (if you need a restart)

Solution 4:[4]

To stop apache process try this command

ps aux | grep tomcat | awk '{print $2}' | xargs kill -9

Solution 5:[5]

For a more graceful way, try the following:

Caveat: I'm running Debian 7, not Ubuntu, though it is a Debian derivative

If you're running Tomcat as a service, you can get a list of all running services by typing:

sudo service --status-all

I'm running Tomcat 7, which is displayed as tomcat7 in said list. Then, to shut it down just type:

sudo service tomcat7 stop

Solution 6:[6]

If you installed tomcat manually, run the shutdown.sh(/.../tomcat/bin) from the terminal to shut it down easily.

Solution 7:[7]

I had a similar problem and found the following command to work:

sudo systemctl stop tomcat

After running this command you can type the following to verify that it is "disabled":

systemctl list-units

output for systemctl list-units

Solution 8:[8]

When running Tomcat under jsvc, it will not respond to the shutdown signal on the specified shutdown port which is sent from the shutdown.sh script. The only way that I'm aware of is to kill the process, however you'll need to kill the ones listed as jsvc, not java.

Solution 9:[9]

if you are run this command

 debian@debian:~$  /usr/share/tomcat7/bin/shutdown.sh
 then your server will not stop and you will get o/p like that you provided if you use in 
 super user mode then effect will appear o/p will come like this

 debian@debian:~$ sudo /usr/share/tomcat7/bin/shutdown.sh
 [sudo] password for debian: 
 Using CATALINA_BASE:   /var/lib/tomcat
 Using CATALINA_HOME:   /var/lib/tomcat
 Using CATALINA_TMPDIR: /var/lib/tomcat/temp
 Using JRE_HOME:        /usr/lib/jvm/java-1.6.0-openjdk
 Using CLASSPATH:   /var/lib/tomcat/bin/bootstrap.jar:/var/lib/tomcat/bin/tomcat-juli.jar

Solution 10:[10]

if you have yout tomcat installed you can do :

sh path2tomcat/bin/shutdown.sh

Solution 11:[11]

To check whether the environment variable for Tomcat is set or not use the following command in the terminal:

echo $CATALINA_HOME

To Start Tomcat:

$CATALINA_HOME/bin/startup.sh

To Stop Tomcat:

$CATALINA_HOME/bin/shutdown.sh

To check Tomcat started or stopped: http://localhost:8080/

SCREENSHOTS: 1.Terminal 2.Tomcat Started 3.Tomcat Stopped

Solution 12:[12]

None of the suggested solutions worked for me.

I had run tomcat restart before completing the deployment which messed up my web app.

EC2 ran tomcat automatically and tomcat was stuck trying to connect to a database connection which was not configured properly.

I just needed to remove my customized context in server.xml, restart tomcat and add the context back in.

Solution 13:[13]

Caveat: I'm running Ubuntu

sudo service --status-all

you can get a list of all running services by typing this command,

If you're running Tomcat as a service it will showes up as ("tomcat"), so run :

sudo service tomcat7 stop

(tomcat7 or 8 or depending to the name that you have in the list of running services )

else and if you are using apache tomcat you will see ("apache2") showing up with the list of services then run :

sudo service apache2 stop