Getting ${HOSTNAME} into application.conf

1,584 views
Skip to first unread message

Kevin Wright

unread,
May 28, 2012, 5:57:42 AM5/28/12
to akka...@googlegroups.com

The question's in the title, has anybody figured a way to do this?

I can "echo ${HOSTNAME}" just fine at the command line, but Akka doesn't pick up on it.
(neither ${HOSTNAME} nor ${?HOSTNAME} resolve for me)

The only way I can think of is to explicitly set another env variable of another name, but that then pushes the problem back onto our infrastructure team, and we'd have to do a puppet refresh across multiple physical nodes.

√iktor Ҡlang

unread,
May 28, 2012, 6:02:38 AM5/28/12
to akka...@googlegroups.com
hi Kevin,

Optional system or env variable overrides

In default uses of the library, exact-match system properties already override the corresponding config properties. However, you can add your own overrides, or allow environment variables to override, using the ${?foo} substitution syntax.

basedir = "/whatever/whatever"
basedir = ${?FORCED_BASEDIR}

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

A natural extension of this idea is to support several different environment variable names or system property names, if you aren't sure which one will exist in the target environment.

Object fields and array elements with a ${?foo} substitution value just disappear if the substitution is not found:

// this array could have one or two elements
path = [ "a", ${?OPTIONAL_A} ]


Does that help?

Cheers,


--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

Kevin Wright

unread,
May 28, 2012, 6:35:03 AM5/28/12
to akka...@googlegroups.com
Sadly not, that's what I'm doing already!

The config block is:

zeebox {
  env = "localhost"
  env = ${?ZEEBOX_ENV}
  hostname = "localhost"
  hostname = ${?HOSTNAME}
  nodename = ${zeebox.component}"-"${zeebox.hostname}
}

env gets correctly resolved, hostname doesn't.  So this is something specific to the HOSTNAME environment variable.

Kevin Wright

unread,
May 28, 2012, 6:43:57 AM5/28/12
to akka...@googlegroups.com
Okay... So it turns out that HOSTNAME is an internal variable provided by bash, and that it's not in the environment as such!  Nor is it is available through java.util.Properties.

The only solutions that seem available now are:
  1. Manually create an environment variable containing the required name
  2. Push the results of `InetAddress.getLocalHost.getHostName` into a system property before the Akka config is loaded.
The second approach intrigues me, as it could be quite powerful.  Has anybody managed to do anything like this before?

--
Kevin Wright
mail: kevin....@scalatechnology.com
gtalk / msn : kev.lee...@gmail.com
vibe / skype: kev.lee.wright
steam: kev_lee_wright

"My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger" ~ Dijkstra

√iktor Ҡlang

unread,
May 28, 2012, 6:46:39 AM5/28/12
to akka...@googlegroups.com
On Mon, May 28, 2012 at 12:43 PM, Kevin Wright <kev.lee...@gmail.com> wrote:
Okay... So it turns out that HOSTNAME is an internal variable provided by bash, and that it's not in the environment as such!  Nor is it is available through java.util.Properties.

The only solutions that seem available now are:
  1. Manually create an environment variable containing the required name
or supplying it in the run-script as a System Property.

 
  1. Push the results of `InetAddress.getLocalHost.getHostName` into a system property before the Akka config is loaded.
The second approach intrigues me, as it could be quite powerful.  Has anybody managed to do anything like this before?

Sure, a lot of times. just do: System.setProperty prior to creating your ActorSystem.

Cheers,
 

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Kevin Wright

unread,
May 28, 2012, 7:10:58 AM5/28/12
to akka...@googlegroups.com
I'm working with Spray in a servlet container.  So creating a listener for this solved the problem nicely...

I must now figure out what else I can do with my new-found powers :)

√iktor Ҡlang

unread,
May 28, 2012, 7:12:53 AM5/28/12
to akka...@googlegroups.com
On Mon, May 28, 2012 at 1:10 PM, Kevin Wright <kev.lee...@gmail.com> wrote:
I'm working with Spray in a servlet container.  So creating a listener for this solved the problem nicely...

I must now figure out what else I can do with my new-found powers :)

lol
 
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.
Reply all
Reply to author
Forward
0 new messages