mashupbots / socko

A Scala web server powered by Netty networking and AKKA processing.
Other
255 stars 51 forks source link

UberJar bundling of SockoWeb and passing external configuation and logback handling #55

Closed conikeec closed 11 years ago

conikeec commented 11 years ago

I am currently bundling socko in a uber-jar via sbt-assembly with the main class specified and abstract the uberjar in a startup script.

java -jar mysockwebserver.jar

I would now like to pass the application.conf and logback.xml as external configuration to mysockwebserver.jar

java -jar mysockwebserver.jar -Dconfig.file=application.conf -Dlogging.file=logback.xml

How would I go about doing this and how would I override the existing application.conf and logback.xml bundled in the uberjar

veebs commented 11 years ago

Hi,

Socko uses the configuration form Akka. Here's the link for customising Akka configuration path: http://doc.akka.io/docs/akka/2.1.4/general/configuration.html#Reading_configuration_from_a_custom_location

A simple way that I've been using is to use the path from the system properties variable, read the file as a string and then pass the contents of the file to akka as follows:

val actorConfig = "Contents of file specified on the command line as system property"
val actorSystem = ActorSystem("WebServerConfigSpec", ConfigFactory.parseString(actorConfig))

For logback, try this: http://logback.qos.ch/manual/configuration.html#configFileProperty

java -Dlogback.configurationFile=/path/to/config.xml

Let me know if this works for you.

conikeec commented 11 years ago

Hi Vibul

Thanks for the detailed note.

The application conf setup (as you recommended above) works !

However I am not able to get the logback config to work. I had an external logback passed to the jar (with a different file system path) and for some reason it still picking the path from the logback.xml embedded in the uberjar

veebs commented 11 years ago

Here are some more links on logback that may help

http://stackoverflow.com/questions/6699537/how-to-use-multiple-configurations-with-logback-in-a-single-project

http://stackoverflow.com/questions/14288623/logback-externalization

conikeec commented 11 years ago

The Logback issue finally worked. It had to do with relative path

http://www.baptiste-wicht.com/2010/08/do-not-use-relative-path-with-logback/

java -Dlogback.configurationFile=/path/to/config.xml (works) java -Dlogback.configurationFile=config.xml in same folder does not work

I will soon be blogging about our experience with Socko. I am throughly pleased with the framework