Search code examples
scalaakkahocon

HOCON not substituting environment variables


I have read the documentation concerning falling back to environment variables at https://github.com/typesafehub/config/blob/master/HOCON.md#substitution-fallback-to-environment-variables. My understanding was that it would pickup any envars. So for instance, if from the shell I was able to do echo $HOSTNAME and see a non-empty response then HOCON should do that as well.

In my application.conf I have a line

akka.remote.netty.tcp.hostname = ${HOSTNAME}

However, my app is not happy with this and fails to start with.

/conf/application.conf: 9: Could not resolve substitution to a value:  ${HOSTNAME}

Is this a user issue? A shell issue? I am able to login as the user and echo $HOSTNAME

Tagging this scala and akka since that userbase probably has the most exposure to HOCON


Solution

  • The reason for HOCON not picking up the envar is that my app runs as a linux service (Centos 6.5) which clears away most environment variables.

    See https://unix.stackexchange.com/questions/44370/how-to-make-unix-service-see-environment-variables for a relevant description of the issue