Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change configuration in distributed playframework application

Currently using playframework 2.0.2 and in my application.conf i set the db connection info

db.default.url="jdbc:mysql://localhost:3306/test"
db.default.driver=com.mysql.jdbc.Driver
db.default.user=test
db.default.pass=test

But what I would like to know is when i put my application into production using "play clean update dist" and then install it on site there is no application.conf. This means that I have to change the db connection before I distribute the code? is there a way to change the db connection in a config file after you have distributed it?

like image 493
user1434177 Avatar asked Nov 02 '12 00:11

user1434177


2 Answers

When you use play dist the config files get packaged into a jar file in the zip. You could create a conf/prod.conf file containing something like:

include "application.conf"

db.default.url="jdbc:mysql://foo.com:3306/mydb"
db.default.driver=com.mysql.jdbc.Driver
db.default.user=foo
db.default.pass=bar

Then when you start the Play app tell it to use the prod.conf file by running:

start -Dconfig.resource=prod.conf
like image 96
James Ward Avatar answered Oct 31 '22 02:10

James Ward


To avoid packaging the config file at all I would suggest that you create a prod.conf on the production servers and store in a folder other than folder you unzip the distributed files to. Then create a startup script like below (or a more sophisticated startup script that start your app as a service). By keeping the config file separate from you dist package you avoid the risk of accidentally overriding it when pushing out new changes.

#!/bin/bash
sh start -Dconfig.file=/path/to/prod.conf &
like image 43
Ola Wiberg Avatar answered Oct 31 '22 01:10

Ola Wiberg