Command-line Tomcat server control with wget and the Tomcat manager
Using wget and the Tomcat manager, you can script remote tomcat deploys, undeploys, starts, stops, and status.
First, make sure the Tomcat manager is installed and running:
In Tomcat 5.5, the manager GUI comes packaged, but not configured. To configure:
cp tomcat5.5/server/webapps/manager/manager.xml tomcat5.5/conf/Catalina/localhost/ vi tomcat5.5/conf/tomcat-users.xml
add:
<role rolename="manager"/>
<user username="admin" password="test1234" roles="tomcat,manager"/>
and now restart Tomcat.
The manager GUI can now be seen at:
http://hostname:8080/manager/html
and you will be prompted for the username and password you provided in the tomcat-users.xml
Status
Now, we can get the status of all deployed apps by running the following command:
wget http://<username>:<password>@<hostname>:<port>/manager/list -O - -q
for example:
wget http://admin:test1234@blojszp1:8080/manager/list -O - -q
shows the status of all applications deployed and running on this particular Tomcat instance:
/balancer:running:0:balancer /testapp:running:0:testapp /host-manager:running:0:/u01/app/tomcat/server/webapps/host-manager /:running:0:ROOT /manager:running:0:/u01/app/tomcat/server/webapps/manager
Undeploy
To undeploy an application, issue the following command:
wget "http://<username>:<password>@<hostname>:<port>/manager/undeploy?path=/<context path>" -O - -q
WARNING!!!!! – the undeploy function will REMOVE the application AND war file from the webapps directory.
For example:
wget "http://admin:test1234@blojszp1:8080/manager/undeploy?path=/testapp" -O - -q OK - Undeployed application at context path /testapp
Deploy
An application can be deployed using a similar command:
wget "http://<user>:<pass>@<host>:<port>/manager/deploy?path=/<context>&war=file:<filepath>" -O - -q
Where the “war=file:” is the path to the war file on the server you are deploying it to. This particular method does not ‘push’ a war file to the destination server.
For example: (this should all be on one line, but for formatting reasons, I had to split it up…)
wget "http://admin:test1234@blojzsp1:8080/manager/deploy?path=/testapp&war=file:/staging/testapp.war" -O - -q OK - Deployed application at context path /testapp
Stop
You can stop a particular application:
wget "http://<username>:<password>@<hostname>:<port>/manager/stop?path=/<context path>" -O - -q
For example:
wget "http://admin:test1234@blojzsp1:8080/manager/stop?path=/testapp" -O - -q OK - Stopped application at context path /testapp
Notice the application shows as ‘stopped’ when you list the applications:
wget http://admin:test1234@blojszp1:8080/manager/list -O - -q /balancer:running:0:balancer /testapp:stopped:0:testapp /host-manager:running:0:/u01/app/tomcat/server/webapps/host-manager /:running:0:ROOT /manager:running:0:/u01/app/tomcat/server/webapps/manager
Start
And to start that application:
wget "http://<username>:<password>@<hostname>:<port>/manager/start?path=/<context path>" -O - -q
For example:
wget "http://admin:test1234@blojzsp1:8080/manager/start?path=/testapp" -O - -q OK - Started application at context path /testapp
