Tomcat reloads webapp from the command line

I have a PCI DSS compatible environment in which several applications are running, and I want to restart only one application without restarting the server. I donโ€™t have a manager, because apparently this is not allowed in this environment.

How do I start restarting a single web application through the command line?

+16
java-ee tomcat
source share
5 answers

I know I'm late for the party, but a little trick you can do to reload the application from the command line is to go to the web.xml of the application and just touch it.

touch web.xml

tomcat reloads the application every time it notices changes in this file, if you just touch it, you do not actually change the file, but only the timestamp.

+26
source share

Here is how I do it:

  • Make sure you have a user with the manager-script role in the tomcat user database. This usually means that you have a line like this in ${TOMCAT}/conf/tomcat-users.xml :
 <user username="admin" password="secret" roles="manager-gui,manager-script"/> 

Otherwise, you will receive a 403 error due to cross-site request forgery protection (CSRF).

  1. Use curl or any command line tool you want to get with URl <yourserver>/manager/text/reload?path=/<context_path> :

     curl --user user:secret http://localhost:8080/manager/text/reload?path=/mypath 
+23
source share

Without access to the managerโ€™s application, you cannot do this. If you can access the control application and still want to use the command line instead of your web browser, you can try this command line script to control tomcat called tomcat-manager. This requires Python, but allows you to do things from a Unix shell, for example:

 $ 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 
+2
source share

Unfortunately, I don't think there is a way to do this from the command line. Instead, I would recommend to see if there is a way to host one application that needs to be restarted in a separate Tomcat instance so that you can restart this instance without affecting other applications.

0
source share

works, change the name app.war to a temporary app.war.bkp (any name for the backup), and then, when tomcat deletes the original webapp folder, change the name .bkp to the original name. this work is for console user only.

0
source share

All Articles