I’m using Erlang for a PA which, among other things, includes a TCP server. To facilitate testing the system with several Erlang nodes running all on the same computer I’d like to have this TCP server listening on the same port but on different IPs (127.0.0.1, 127.0.0.2, &c).
I searched a bit and Application parameters (app(4) env config, application:get_env/3) seem to be what I need: application:get_env(my_application, ipaddr, {127, 0, 0, 1}). In the my_application.app.src file I can specify these variables already, it works!
However, for the original goal of running the same application several times on the same computer, I was looking for a way to specify/override these defaults with the rebar3 shell command. I searched online but still haven’t found a good way to do this.
More specifically, I tried using rebar3 shell --config but haven’t figured out how because it doesn’t work for me. I’ve tried using -my_application ipaddr '{127, 0, 0, 2}' as suggested in the erl docs but rebar3 complains that it’s an invalid option (fair enough).
I’ve also tried using the ERL_FLAGS OS environment variable (suggested here), which seems to be working(!) but isn’t very ergonomic (have to deal to shell expansion &c…).
Is there no other way? Being able to use a config file for each node would be ideal, so that I could more easily edit and use more complex Erlang terms as values. rebar3 shell --config looks exactly like what I want, but I can’t understand how I’m supposed to use it…
I had found this config parameter, but the problem is how to change it on each rebar3 shell invocation, to start different nodes with different configs.
Thanks for the reply, I didn’t know about the peer module, will investigate it.
RE the --config option, can you provide an “template” sys.config? Is it similar to rebar.config in content? Asking because I’ve already tried using this option but failed.
Yes, but only when running releases and it is allowed by relx’s sys_config_src option which allows you to specify template configuration file. It uses a simple templating system allowing you to embed your env variables into resulting sys.config. However, there is no option to do it when running rebar3 shell. Can someone provide more info on why this is missing and whether there is interest to add --config_src option to rebar3 shell command?
Because environment variables are not as ergonomic to use as application parameters. Depending on the option, you may need to do extra processing (such as parsing a number or an IP address). With the proposed solution I went with you get Erlang terms out of the config variables.