33

I have a PCI DSS compliant environment which runs several apps and I want to restart only one app without restarting the server. I don't have the manager because apparently it's not allowed in this environment.

How do I go about restarting a single web app via command line?

Matthew Green
  • 10,161
  • 4
  • 36
  • 54
Itai Sagi
  • 5,537
  • 12
  • 49
  • 73
  • 2
    Possible duplicate of [What's an easy, quick way to reload a webapp in tomcat in dev environment?](https://stackoverflow.com/questions/1800784/whats-an-easy-quick-way-to-reload-a-webapp-in-tomcat-in-dev-environment) – rogerdpack Oct 12 '17 at 16:23

5 Answers5

60

I know I am late to the party, but a little trick you can do in order to reload the app from the command line is to go to the web.xml of the application and simply touch it.

cd webapps/<webapp-name>/WEB-INF/

touch web.xml

tomcat reloads the application every time it notices a change on this file, if you simply touch it, you are not actually modifying the file, just the timestamp.

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Ulukai
  • 1,360
  • 2
  • 12
  • 17
  • 7
    This is true only if you have the attribute `autoDeploy=true` on your `` element (by default). – Ortomala Lokni Feb 21 '17 at 13:36
  • 1
    I believe you want to say that this redeploys the app. If you go and change a property file in the exploded war directory and then touch the war, it will redeploy, resetting all your changes with the ones originally in the war. – jbu Mar 17 '17 at 19:38
35

Here's how I do it:

  1. Ensure that you have user with "manager-script" role in your tomcat user database. That usually means that you have line like this in your ${TOMCAT}/conf/tomcat-users.xml :
<user username="admin" password="secret" roles="manager-gui,manager-script"/>

Otherwise, you will get a 403 error because of cross-site request forgery (CSRF) protection.

  1. Use curl or whatever command line tool you like to fetch the URl <yourserver>/manager/text/reload?path=/<context_path>:

    curl --user user:secret http://localhost:8080/manager/text/reload?path=/mypath  
    
laurent
  • 674
  • 9
  • 14
2

Without access to the manager application, you can't do it. If you can get access to the manager application, and still want to use the command line instead of your web browser, you can 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/ reload /myapp

and:

$ tomcat-manager --user=admin --password=newenglandclamchowder \
> http://localhost:8080/manager deploy /myapp ~/src/myapp/myapp.war
kotfu
  • 161
  • 1
  • 3
0

Unfortunately I do not think there is a way to do this from the command line. Instead, I would recommend seeing if there is a way to host the single application you need to restart in a separate instance of Tomcat so you can restart that instance without affecting the other applications.

Zeleres
  • 170
  • 3
  • 10
0

works change the name of the app.war to temp app.war.bkp(any name for backup) and then when tomcat delete the source folder of webapp change the name of .bkp to original name. this work only for console access user.