Stop a web application tomcat from command line
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
- With local access you can of course just stop the process. This stops tomcat entirely
- 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.
- You follow sam's advice, which lets you be selective.
Related videos on Youtube
![Michael Küller](https://i.stack.imgur.com/2pj1S.jpg?s=256&g=1)
Comments
-
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 about 12 yearsDo you want to stop Tomcat locally or remotely?
-
Michael Küller about 12 yearsI just want to stop it locally
-
-
Michael Küller about 12 yearsStopping 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 about 12 yearsThis 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 about 12 yearsThen 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 about 11 yearsMy stop URL should contain "org.apache.catalina.filters.CSRF_NONCE" token. It complicates this approach.
-
Haroldo_OK about 10 yearsKotfu's answer better details this.
-
Erica Kane over 5 yearsAnd if you have a parallel deployment, with the hashtag sign (#), remember that you must URL encode it to %23 in the path.