How do I supply configuration to elastic beanstalk tomcat

前端 未结 2 707
面向向阳花
面向向阳花 2020-12-09 19:10

when deploying locally to tomcat, I make this change (below) to server.xml, is there a way I can supply this to Elastic Beanstalk?



        
相关标签:
2条回答
  • 2020-12-09 19:24

    You can do it now without providing custom AMI. Follow instructions in: http://aws.typepad.com/aws/2012/10/customize-elastic-beanstalk-using-configuration-files.html

    In order to provide custom server xml create .ebextensions folder in webapp, put there custom server.xml file and add one more file: server-update.config with content:

    container_commands:
      replace-config:
      command: cp .ebextensions/server.xml /etc/tomcat7/server.xml
    
    0 讨论(0)
  • 2020-12-09 19:47

    Another way to implement this without replacing the entire Tomcat server.xml file is using the following in your .ebextensions folder (e.g. tomcat.config)

    files:
      "/tmp/update_tomcat_server_xml.sh":
        owner: root
        group: root
        mode: "000755"
        content: |
          #! /bin/bash
          CONFIGURED=`grep -c '<Connector port="8080" URIEncoding="UTF-8"' /etc/tomcat7/server.xml`
          if [ $CONFIGURED = 0 ]
            then
              sed -i 's/Connector port="8080"/Connector port="8080" URIEncoding="UTF-8"/' /etc/tomcat7/server.xml
              logger -t tomcat_conf "/etc/tomcat7/server.xml updated successfully"
              exit 0
            else
              logger -t tomcat_conf "/etc/tomcat7/server.xml already updated"
              exit 0
          fi
    
    container_commands:
      00_update_tomcat_server_xml:
        command: sh /tmp/update_tomcat_server_xml.sh
    

    This config creates a script (files) and then runs it (container_command). The script checks the server.xml for the UIREncoding="UTF8" string and if it doesn't find it, it then adds it in using the sed command.

    The nice thing about this solution is that if you upgrade your version of Tomcat (e.g. from 7 to 8) then you don't have to worry about updating the server.xml in your various WAR files.

    Also, this example is for adding the UIREncoding parameter but the script is very easily adapted to add <Connector ... />' property from the original question.

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