fix(mgmt): allow binding to specific interface

When one tries to define the management http listener as, for example,
`172.25.0.2:8081`, ranch is given `{port, {"172.25.0.2",8081}}` and
breaks.

```sh
env EMQX_MANAGEMENT__LISTENER__HTTP=172.25.0.2:8081 make quickrun
```

```
2022-05-20T13:14:19.451272-03:00 [error] Supervisor: {<0.2485.0>,ranch_listener_sup}. Context: start_error. Reason: badarg. Offender: id=ranch_acceptors_sup,pid=undefined.
2022-05-20T13:14:19.451400-03:00 [error] crasher: initial call: supervisor:ranch_acceptors_sup/1, pid: <0.2487.0>, registered_name: [], exit: {badarg,[{inet_tcp,listen,2,[{file,"inet_tcp.erl"},{line,166}]},{ranch_acceptors_sup,init,1,[{file,"ranch_acceptors_sup.erl"},{line,39}]},{supervisor,init,1,[{file,"supervisor.erl"},{line,330}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,423}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,390}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}, ancestors: [<0.2485.0>,ranch_sup,<0.2187.0>], message_queue_len: 0, messages: [], links: [<0.2485.0>], dictionary: [{logger,error_logger}], trap_exit: true, status: running, heap_size: 610, stack_size: 29, reductions: 612; neighbours:
2022-05-20T13:14:19.451754-03:00 [error] Minirest(Handler): Start http:management listener on {"172.25.0.2",8081} unsuccessfully:
```

So, it’s currently not possible to make the management listener bind
to a specific interface.
This commit is contained in:
Thales Macedo Garitezi 2022-05-20 16:14:23 -03:00
parent 5e3b0cf2d8
commit e57e2f68d4
No known key found for this signature in database
GPG Key ID: DD279F8152A9B6DD
1 changed files with 7 additions and 1 deletions

View File

@ -227,6 +227,13 @@ end}.
Prefix = "management.listener." ++ atom_to_list(Proto), Prefix = "management.listener." ++ atom_to_list(Proto),
case cuttlefish:conf_get(Prefix, Conf, undefined) of case cuttlefish:conf_get(Prefix, Conf, undefined) of
undefined -> Acc; undefined -> Acc;
{IPStr, Port} ->
{ok, IP} = inet:parse_address(IPStr),
[{Proto, Port, [{ip, IP}] ++ TcpOpts(Prefix) ++ Opts(Prefix)
++ case Proto of
http -> [];
https -> SslOpts(Prefix)
end} | Acc];
Port -> Port ->
[{Proto, Port, TcpOpts(Prefix) ++ Opts(Prefix) [{Proto, Port, TcpOpts(Prefix) ++ Opts(Prefix)
++ case Proto of ++ case Proto of
@ -236,4 +243,3 @@ end}.
end end
end, [], [http, https]) end, [], [http, https])
end}. end}.