Distributed application testing: How best to set the node name for each application instance?

I can fudge it by having 2 separate release builds of the same code, each with its own vm.args file that sets the sname flag. But I’d like to only have to build one release image, then set the sname when running it.

The command I’m using to start the application on each node (both on localhost) is:
_build/default/rel/<app>/bin/<app> daemon

I’m sure I am missing a trick.

3 Likes

This is a knowd and somewhat annoying issue with relx “extended startup script”.
There are a few options available.
If you want to keep the extended startup script, you can mv vm.args vm.args.src and set the node name there using environment variable (e.g. -sname $NODE).

If you don’t really need extended startup script, then you can start your node with ERL_FLAGS="-sname name" (you’d need to add {extended_start_script, false} to rebar.config section relx).

Or, you can circumvent relx startup script and start the node directly (with erlexec, basically see what the bin/<app> script does - it essentially is a layer on top of erlexec).

One more alternative is to build the release with systools (not with relx), see the Docker example here. While peer has not yet been released, the technique from the example works just fine without peer.

4 Likes

Maybe it would be possible to use ERL_AFLAGS? That is:

ERL_AFLAGS="-name nodename" _build/default/rel/<app>/bin/<app> daemon
4 Likes

Thanks both. I will have a play with the suggested options as soon as I get chance and report back on what works best for me.

2 Likes

This does not work with “extended startup script”, as relx wants a hardcoded node name (e.g. for running remote shell).

3 Likes