Documentation

You are viewing the documentation for the 2.4.0-M2 development release. The latest stable release series is 3.0.x.

§Additional configuration

When running an application in production mode you can override any configuration. This section covers the more common use cases.

All these additional configurations are specified using Java System properties and can be used directly if you are using one of the start scripts generated by Play.

§Specifying the HTTP server address and port

You can provide both HTTP port and address. The default is to listen on port 9000 at the 0.0.0.0 address (all addresses).

$ /path/to/bin/<project-name> -Dhttp.port=1234 -Dhttp.address=127.0.0.1

Note that these configuration are only provided for the default embedded Netty server.

§Specifying additional JVM arguments

You can specify any JVM arguments to the start script. Otherwise the default JVM settings will be used:

$ /path/to/bin/<project-name> -J-Xms128M -J-Xmx512m -J-server

As a convenience you can also set memory min, max, permgen and the reserved code cache size in one go; a formula is used to
determine these values given the supplied parameter (which represents maximum memory):

$ /path/to/bin/<project-name> -mem 512 -J-server

§Specifying alternative configuration file

The default is to load the application.conf file from the classpath. You can specify an alternative configuration file if needed:

§Using -Dconfig.resource

It will search for an alternative configuration file in the application classpath (you usually provide these alternative configuration files into your application conf/ directory before packaging). Play will look into conf/ so you don’t have to add conf/.

$ /path/to/bin/<project-name> -Dconfig.resource=prod.conf

§Using -Dconfig.file

You can also specify another local configuration file not packaged into the application artifacts:

$ /path/to/bin/<project-name> -Dconfig.file=/opt/conf/prod.conf

§Using -Dconfig.url

You can also specify a configuration file to be loaded from any URL:

$ /path/to/bin/<project-name> -Dconfig.url=http://conf.mycompany.com/conf/prod.conf

Note that you can always reference the original configuration file in a new prod.conf file using the include directive, such as:

include "application.conf"

key.to.override=blah

§Overriding specific configuration keys

Sometimes you don’t want to specify another complete configuration file, but just override a bunch of specific keys. You can do that by specifying then as Java System properties:

$ /path/to/bin/<project-name> -Dapplication.secret=abcdefghijk -Ddb.default.password=toto

§Using environment variables

You can also reference environment variables from your application.conf file:

my.key = defaultvalue
my.key = ${?MY_KEY_ENV}

Here, the override field my.key = ${?MY_KEY_ENV} simply vanishes if there’s no value for MY_KEY_ENV, but if you set an environment variable MY_KEY_ENV for example, it would be used.

§Changing the logback configuration file

§Bundling a custom logback configuration file with your application

Create an alternative logback config file called application-logger.xml and copy that to <app>/conf

You can also specify another logback configuration file via a System property. Please note that if the configuration file is not specified then play will use the default logger.xml that comes with play in the production mode. This means that any log level settings in application.conf file will be overridden. As a good practice always specify your application-logger.xml.

§Using -Dlogger.resource

Specify another logback configuration file to be loaded from the classpath:

$ /path/to/bin/<project-name> -Dlogger.resource=conf/prod-logger.xml

§Using -Dlogger.file

Specify another logback configuration file to be loaded from the file system:

$ /path/to/bin/<project-name> -Dlogger.file=/opt/prod/prod-logger.xml

§Using -Dlogger.url

Specify another logback configuration file to be loaded from an URL:

$ /path/to/bin/<project-name> -Dlogger.url=http://conf.mycompany.com/logger.xml

§Changing the path of RUNNING_PID

It is possible to change the path to the file that contains the process id of the started application. Normally this file is placed in the root directory of your play project, however it is advised that you put it somewhere where it will be automatically cleared on restart, such as /var/run:

$ /path/to/bin/<project-name> -Dpidfile.path=/var/run/play.pid

Make sure that the directory exists and that the user that runs the Play application has write permission for it.

Using this file, you can stop your application using the kill command, for example:

$ kill $(cat /var/run/play.pid)

§Advanced HTTP server configuration

The Play HTTP server can be tuned in a number of ways via system properties.

Note: You cannot use application.conf to configure the HTTP server properties.

The following HTTP protocol options are supported:

http.netty.maxInitialLineLength
The maximum length for the initial line of an HTTP request, defaults to 4096
http.netty.maxHeaderSize
The maximum size for the entire HTTP header, defaults to 8192
http.netty.maxChunkSize
The maximum size that Netty will buffer body chunks before splitting them, defaults to 8192
http.netty.log.wire
Activate logging of Netty channel events, defaults to false. This option is useful to debug the HTTP packets. To see the log traces, the org.jboss.netty.handler.logging.LoggingHandler logger must be set to DEBUG in the logback configuration file.

Play also allows configuring the full list of TCP socket options that Netty supports, by prefixing them with http.netty.option. Note that socket options that should be applied to sockets of accepted connections should have an additional child prefix before the option. Here are some common ones:

http.netty.option.child.keepAlive
Set to true/false to turn on/off TCP keep alive
http.netty.option.backlog
Configure the maximum size for queued incoming connections

For a full list of supported options, see the following Netty documentation:

Next: Setting up a front end HTTP server