MikeW
MikeW

Reputation: 4809

How do I supply configuration to elastic beanstalk tomcat

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

<Connector connectionTimeout="20000" port="8080" 
       protocol="org.apache.coyote.http11.Http11NioProtocol" 
       redirectPort="8443"/>'

thanks '

Upvotes: 18

Views: 19494

Answers (2)

bobmarksie
bobmarksie

Reputation: 3626

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.

Upvotes: 19

Maciej Walkowiak
Maciej Walkowiak

Reputation: 12932

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

Upvotes: 33

Related Questions