Tomcat manager remote deploy script

前端 未结 6 2062
故里飘歌
故里飘歌 2020-11-28 21:45

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.htm

相关标签:
6条回答
  • 2020-11-28 22:01

    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?).

    0 讨论(0)
  • 2020-11-28 22:06

    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

    0 讨论(0)
  • 2020-11-28 22:09

    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
    
    0 讨论(0)
  • 2020-11-28 22:19

    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!
    0 讨论(0)
  • 2020-11-28 22:21

    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
    
    0 讨论(0)
  • 2020-11-28 22:23

    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

    0 讨论(0)
提交回复
热议问题