Michael Küller
Michael Küller

Reputation: 3994

Stop a web application tomcat from command line

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?

Upvotes: 22

Views: 51402

Answers (6)

Markus
Markus

Reputation: 6288

In some cases the pragmatic way can be to simply remove or rename the respective war-file, so tomcat undeploys the app.

Upvotes: 0

MattC
MattC

Reputation: 6324

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

Upvotes: 13

Philippe RUAUDEL
Philippe RUAUDEL

Reputation: 116

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

Upvotes: 9

kotfu
kotfu

Reputation: 171

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.

Upvotes: 12

MJB
MJB

Reputation: 9389

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.

Upvotes: 3

Sam
Sam

Reputation: 2969

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

Upvotes: 12

Related Questions