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

**URL:** <https://erlangforums.com/t/distributed-application-testing-how-best-to-set-the-node-name-for-each-application-instance/969>\
**Category:** Questions / Help\
**Tags:** distributed-erlang, erlang-nodes\
**Created:** [January 22, 2022, 5:39pm UTC](https://erlangforums.com/t/distributed-application-testing-how-best-to-set-the-node-name-for-each-application-instance/969 "2022-01-22T17:39:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phild](https://erlangforums.com/user_avatar/erlangforums.com/phild/32/742_2.png) [@phild](https://erlangforums.com/u/phild)\
**Post date:** [January 22, 2022, 5:39pm UTC](https://erlangforums.com/t/distributed-application-testing-how-best-to-set-the-node-name-for-each-application-instance/969/1 "2022-01-22T17:39:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![max-au](https://erlangforums.com/user_avatar/erlangforums.com/max-au/32/1627_2.png) [@max-au](https://erlangforums.com/u/max-au)\
**Post date:** [January 24, 2022, 5:09am UTC](https://erlangforums.com/t/distributed-application-testing-how-best-to-set-the-node-name-for-each-application-instance/969/2 "2022-01-24T05:09:32Z")

</div>

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](https://github.com/erlang/otp/blob/master/lib/stdlib/doc/src/peer.xml#L207). While `peer` has not yet been released, the technique from the example works just fine without `peer`.

---

<div class="post-metadata">

**Author:** ![garazdawi](https://erlangforums.com/user_avatar/erlangforums.com/garazdawi/32/175_2.png) [@garazdawi](https://erlangforums.com/u/garazdawi)\
**Post date:** [January 24, 2022, 8:24am UTC](https://erlangforums.com/t/distributed-application-testing-how-best-to-set-the-node-name-for-each-application-instance/969/3 "2022-01-24T08:24:15Z")

</div>

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

```erlang
ERL_AFLAGS="-name nodename" _build/default/rel/<app>/bin/<app> daemon

```

---

<div class="post-metadata">

**Author:** ![phild](https://erlangforums.com/user_avatar/erlangforums.com/phild/32/742_2.png) [@phild](https://erlangforums.com/u/phild)\
**Post date:** [January 24, 2022, 9:30am UTC](https://erlangforums.com/t/distributed-application-testing-how-best-to-set-the-node-name-for-each-application-instance/969/4 "2022-01-24T09:30:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![max-au](https://erlangforums.com/user_avatar/erlangforums.com/max-au/32/1627_2.png) [@max-au](https://erlangforums.com/u/max-au)\
**Post date:** [January 24, 2022, 5:38pm UTC](https://erlangforums.com/t/distributed-application-testing-how-best-to-set-the-node-name-for-each-application-instance/969/5 "2022-01-24T17:38:11Z")

</div>

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