Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tomcat restart webapp from command line

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?

like image 968
Itai Sagi Avatar asked Sep 27 '12 13:09

Itai Sagi


People also ask

How do you restart Tomcat?

Open the Services window (C:\Windows\system32\services. msc). Locate IDM Apps Tomcat Service. Select Start, Stop, or Restart.


3 Answers

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.

like image 177
Ulukai Avatar answered Sep 30 '22 20:09

Ulukai


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
like image 28
kotfu Avatar answered Sep 30 '22 20:09

kotfu


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  
    
like image 36
laurent Avatar answered Sep 30 '22 19:09

laurent