erlware / relx

Sane, simple release creation for Erlang
http://erlware.github.io/relx
Apache License 2.0
697 stars 232 forks source link

Fix undesired start of epmd when calling relx_get_nodename #744

Closed colrack closed 5 years ago

colrack commented 5 years ago

I don't have epmd started on my machine and I don't want epmd to start from a release. If you set -start_epmd false in your vm.args I expect epmd not to start, like this:

/tmp/athc # ./bin/athcontroller console
Protocol 'inet_tcp': register/listen error: /tmp/athc #

Instead, because of an earlier call to relx_get_nodename here: https://github.com/erlware/relx/blob/f6bdffcd9bff0b62f3b7fd7bbf3db034f05fbd66/priv/templates/extended_bin#L497 the result is an unwanted start of epmd. The solution I propose is to pass ${START_EPMD} to erl inside relx_get_nodename so if -start_epmd is set to false we do not start epmd, rather we exit. Of course if you already have an instance of epmd running this works anyway.

tsloughter commented 5 years ago

Hm, I'm going to have to look at this more thoroughly because I swear epmd isn't started when I use epmdless, and did a good bit of work to ensure that and to ensure stuff like cookies weren't created randomly. So I'm surprised this patch is needed.

colrack commented 5 years ago

More info here: This happens only if you start the node with short names (-sname); with long names the patch is not needed. Here the steps to reproduce:

docker run --rm -it erlang:22.0-alpine sh
/ # rebar3 version
rebar 3.11.1 on Erlang/OTP 22 Erts 10.4.1
/ # rebar3 new app myapp
===> Writing myapp/src/myapp_app.erl
===> Writing myapp/src/myapp_sup.erl
===> Writing myapp/src/myapp.app.src
===> Writing myapp/rebar.config
===> Writing myapp/.gitignore
===> Writing myapp/LICENSE
===> Writing myapp/README.md
/ # cd myapp/
### add relx to rebar.config
/myapp # cat rebar.config
{erl_opts, [debug_info]}.
{deps, []}.

{shell, [
  % {config, "config/sys.config"},
    {apps, [myapp]}
]}.

{relx, [{release, {myapp, "0.1.0"},
         [myapp]},
        {vm_args, "config/vm.args"},
        {include_erts, true},
        {extended_start_script, true}]
}.
### add vm.args
/myapp # cat config/vm.args
-sname node1
-setcookie secret
-start_epmd false
/myapp # rebar3 release
===> Verifying dependencies...
===> Compiling myapp
===> Starting relx build process ...
===> Resolving OTP Applications from directories:
          /myapp/_build/default/lib
          /usr/local/lib/erlang/lib
===> Resolved myapp-0.1.0
===> Including Erts from /usr/local/lib/erlang
===> release successfully created!
/myapp # cd /myapp/_build/default/rel/myapp/
/myapp/_build/default/rel/myapp # ps a
PID   USER     TIME  COMMAND
    1 root      0:00 sh
  203 root      0:00 ps a
/myapp/_build/default/rel/myapp # ./bin/myapp
Usage: myapp {start|start_boot <file>|foreground|stop|restart|reboot|pid|ping|console|console_clean|console_boot <file>|attach|remote_console|upgrade|downgrade|install|uninstall|versions|escript|rpc|rpcterms|eval|status|undefined}
/myapp/_build/default/rel/myapp # ps a
PID   USER     TIME  COMMAND
    1 root      0:00 sh
  250 root      0:00 /myapp/_build/default/rel/myapp/erts-10.4.1/bin/epmd -daemon
  282 root      0:00 ps a
tsloughter commented 5 years ago

Sorry I didn't get back to you on this sooner.

I think the solution should be to check the vm.args for the -start_epmd false setting and include it when running those commands instead of adding a new environment variable.

tsloughter commented 5 years ago

Argh, my bad, that is already how START_EPMD is set, ignore my last comment.

tsloughter commented 5 years ago

And I just realized why I hadn't seen this issue before when using releases that don't start epmd and it is because I'd have set the full node name which keeps it from calling relx_get_nodename.