41

I'm writing a shell script to auto deploy/undeploy using the tomcat manager.

Following the instructions on http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Deploy_A_New_Application_Remotely, I use curl for my deployment

curl --anyauth -u username:pwd -d path=/something -d war=file:target/someWar.war https://someurl.com/manager/deploy

And I get the response saying HTTP method POST is not supported by this URL.

So I change my curl to be a get using -G

curl --anyauth -u username:pwd -G -d path=/something -d war=file:target/someWar.war https://someurl.com/manager/deploy

I get a response of FAIL - Failed to deploy application at context path /something and it seems to be looking for the file locally on the server instead of my machine. There are pluings which do remote deploy without having to scp the file over so I'm wondering what I'm missing.

I'm currently out of ideas (I don't see any other option on the tomcat manager configuration page).

6 Answers 6

58

Providing an update to this question.

Tomcat 7 has changed it's manager API.

Please refer to: Manager commands

Following new URL pattern :

http://{host}:{port}/manager/text/{command}?{parameters}

Example

curl -T "myapp.war" "http://manager:manager@localhost:8080/manager/text/deploy?path=/myapp&update=true"

Security

Keep in mind the server must be able to accept your remote IP. This is a sample configuration:

<Context privileged="true" antiResourceLocking="false"
         docBase="${catalina.home}/webapps/manager">
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.0\.0\.1" />
</Context>

This is an optional setting and isn't required but having Cross domain role and proper manager credentials is a must.

Tomcat 8 - the same rules apply as Tomcat 7. Same commands.

Here is a full documentation:

http://tomcat.apache.org/tomcat-8.0-doc/manager-howto.html

6
  • 9
    It should be noted that the user deploying to tomcat needs to have manager-script role enabled in order to access the text interface.
    – Franklin
    Apr 14, 2014 at 17:53
  • can we do this for deploying in a remote machine tomcat?
    – jos
    Jul 4, 2014 at 10:33
  • @jos You absolutely can. As long as your firewall allows connection from outside. You're also encouraged to use HTTPS
    – jeveloper
    Aug 11, 2014 at 18:22
  • this saves me a lot of time when deploying to a remote machine which has a cluster (same WAR for every instance) and for which I have ssh access Dec 17, 2014 at 11:24
  • @RiccardoCossu I'm happy to hear that.
    – jeveloper
    Dec 18, 2014 at 14:36
45

This way is working for me on Tomcat 6 (See jevelopers answer for tomcat 7):

curl --upload-file <path to warfile> "http://<tomcat username>:<tomcat password>@<hostname>:<port>/manager/deploy?path=/<context>&update=true"

Example:

curl --upload-file target\debug.war "http://tomcat:tomcat@localhost:8088/manager/deploy?path=/debug&update=true"

Very easy peasy. Output is like this:

OK - Undeployed application at context path /debug
OK - Deployed application at context path /debug
4
  • 1
    Got my info from the cURL manual: curl.haxx.se/docs/httpscripting.html check out section 5
    – s3v1
    Mar 7, 2011 at 17:43
  • 2
    This does not work for Tomcat 7. Take a look at the answer from jeveloper
    – Michael R
    Apr 3, 2013 at 14:51
  • 1
    Thanks, Michael R! I updated the text to say Tomcat 6 and added reef to jevelopers answers... just in case someone doesn't read comments
    – s3v1
    Apr 9, 2013 at 16:18
  • thanks a lot! I confirm it works on Tomcat 8.5.29 as follows: curl.exe -v -u "user:pass" --upload-file /path/to/my-war.war "localhost:8080/manager/text/deploy?path = /my-context-path&update = true"
    – a.parfenov
    Apr 4, 2018 at 15:31
3

For those who use Jenkins and want to deploy using shell script in GitBash on a Windows machine instead of Jenkins deploy plugin

tomcat_host=192.10.10.100
tomcat_port=8080
tomcat_username=admin
tomcat_password=12345

context_path=myApplication

curl -v -u ${tomcat_username}:${tomcat_password} -T ${artifact} 'http://'${tomcat_host}':'${tomcat_port}'/manager/text/deploy?path=//'${context_path}''

Note:

  1. curl -v option is verbose (optional)
  2. // two forward slashes before the context path works for GitBash on a Windows machine (/ single forward slash will not somehow)
  3. Also when deploying on a remote server, consider your firewall yeah!
1
  • Pretty sure you want tomcat_username and tomcat_password after the -u in this script, and not the host and port. Feb 2, 2016 at 20:03
3

Improving Jet answer, this works for me in tomcat 8, java 64 bits.

This was what I execute:

curl -v -u some_user:some_password -T /../my_app.war 'http://127.0.0.1:tomcat_port/manager/text/deploy?path=/my_app&update=true'

This will work if we configure tomcat users in :

/.../.../apache-tomcat-8.5.0_001/conf/tomcat-users.xml

with:

<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>

<user username="some_user" password="some_password" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>

Restart tomcat and it will be ready to deploy wars from remote clients like curl, jenkins, travis, etc

1

The easiest way to deploy an app is to write an Ant script. The only other thing (apart from Ant) you will need is catalina-ant.jar to be present in the classpath.

Have a look at this chapter of the manual: http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Executing_Manager_Commands_With_Ant

The script does a similar thing: uses HTTP to deploy your .war to the manager app. You might even want to capture the packets to see the exact headers if you still want to use curl. I would not recommend curl though as I think Ant solution is more portable and error-prone (e.g what if they will change low level deployment API?).

3
  • Thanks for the response. I guess as a worst case scenario I will use ant, but it would be nice to use some sort of deploy mechanism without any dependencies (easier to scale out).
    – bluesman
    Dec 14, 2010 at 16:20
  • The catalina-ant.jar is part of every Tomcat installation so I am not sure if understood your point. Even if you (re)deploy thousands of webapps every day, the overhead of launching JVM should be negligible.
    – mindas
    Dec 14, 2010 at 16:38
  • 1
    We're not concerned about the server, to deploy using ant you still need ant installed on the client machine.
    – bluesman
    Dec 15, 2010 at 4:29
0

I was getting error

curl: Can't open webapp.war 

when I only mentioned

curl -T 'webapp.war'

But it worked when I used the complete path of build artifact like

curl -T ./target/webapp.war

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.