Set inet_dist_listen_min inet_dist_listen_max programmatically. How?

Hello all!
Is there any way to set inet_dist_listen_min and inet_dist_listen_max programmatically?
Very aware of settings via command line and .erlang file. But seeking option to do it exactly from code.

2 Likes

A shell script sounds pragmatic to me :slight_smile: That’s what most of us are doing in one way or another, I would venture to say.

These are application environment variables. They should be possible to set in the start config file.

Programatically they have to be set before the Kernel application starts, and I think no “user” code can do that since that runs after all OTP applications have started.

1 Like

Technically you can’t set these before kernel application starts.
But you can work it around by starting distribution dynamically. There are several ways to achieve that: you can either omit -name and -sname arguments in the command line, or specify -kernel start_distribution false argument there.

Somewhere on your application startup path you can call application:set_env(kernel, inet_dist_listen_min, ...) and then call net_kernel:start(mynode, #{....args...}), to start the distribution dynamically.

3 Likes