Stop a web application tomcat from command line

45,916

Solution 1

The easiest method I know of is to install the Tomcat manager webapp, note the URL for stopping an application, and wget that URL.

Solution 2

Another way is to use CURL. In my case, I am on a corporate Windows machine that does not have WGET. I do have CURL though, and can use it via the GIT BASH terminal.

To list the applications running on Tomcat, I run the following (with user:password)

curl --user admin:admin http://localhost:8080/manager/text/list

Then to stop an application named "myapp"

curl --user admin:admin http://localhost:8080/manager/text/stop?path=/myapp

Solution 3

Try this command-line script for managing tomcat called tomcat-manager. It requires Python, but allows you to do stuff from a Unix shell like:

$ tomcat-manager --user=admin --password=newenglandclamchowder \
> http://localhost:8080/manager/ stop /myapp

and:

$ tomcat-manager --user=admin --password=newenglandclamchowder \
> http://localhost:8080/manager deploy /myapp ~/src/myapp/myapp.war

Because it talks to tomcat over HTTP, it works "locally", i.e. via localhost, or from anywhere your tomcat instance is accessible.

Solution 4

I use wget to stop and start applications. The user in tomcat-user.xml must have manager-script roles.

For TOMCAT 5/6:

wget "http://<user>:<password>@<servername>:<port>/manager/stop?=/<application context>" -O - -q
wget "http://<user>:<password>@<servername>:<port>/manager/start?=/<application context>" -O - -q

Since TOMCAT 7 (7.0.62 for my installation) you have to add /text/ after manager:

wget "http://<user>:<password>@<servername>:<port>/manager/text/stop?path=/<application context>" -O - -q
wget "http://<user>:<password>@<servername>:<port>/manager/text/start?path=/<application context>" -O - -q

Solution 5

There are three ways to stop tomcat application

  1. With local access you can of course just stop the process. This stops tomcat entirely
  2. With local and remote access you can access the "shutdown port", defined in server.xml (default=8005) alon with its password. If you open a socket to this and send the password, tomcat shuts down entirely.
  3. You follow sam's advice, which lets you be selective.
Share:
45,916

Related videos on Youtube

Michael Küller
Author by

Michael Küller

Systems Engineer and Developer

Updated on October 11, 2020

Comments

  • Michael Küller
    Michael Küller over 3 years

    I'm writing a bash script that automatically deploys an application to a tomcat server. How can I stop the application from bash / command line?

    • Christopher Schultz
      Christopher Schultz about 12 years
      Do you want to stop Tomcat locally or remotely?
    • Michael Küller
      Michael Küller about 12 years
      I just want to stop it locally
  • Michael Küller
    Michael Küller about 12 years
    Stopping tomcat entirely is not my goal. I do want to be selective, because I don't want to stop any other applications that are running in parallel
  • Christopher Schultz
    Christopher Schultz about 12 years
    This is the correct answer: if you want to stop an individual webapp, then you'll have to use the internal APIs of Tomcat to do it or use JMX. The Manager webapp is all set up for everything you want to do, and it's easy to configure security for the manager webapp, too.
  • MJB
    MJB about 12 years
    Then sam's advice is the correct one. Be aware that it's very easy for an app server to leak memory with undeploy/redeploy scenarios...
  • Soid
    Soid about 11 years
    My stop URL should contain "org.apache.catalina.filters.CSRF_NONCE" token. It complicates this approach.
  • Haroldo_OK
    Haroldo_OK about 10 years
    Kotfu's answer better details this.
  • Erica Kane
    Erica Kane over 5 years
    And if you have a parallel deployment, with the hashtag sign (#), remember that you must URL encode it to %23 in the path.