I'm trying to setup clustering between a few elixir nodes. My understanding is that I can set this up by modifying the release vm.args. I'm using Distillery to build releases and am following the documentation here: https://hexdocs.pm/distillery/config/vm.args.html.
My rel/vm.args
file is as follows:
-name <%= release_name %>@${HOSTNAME}
-setcookie <%= release.profile.cookie %>
-smp auto
-kernel inet_dist_listen_min 9100 inet_dist_listen_max 9155
-kernel sync_nodes_mandatory '[${SYNC_NODES_MANDATORY}]'
I have a build server running Ubuntu 18.04 and two webservers running Ubuntu 18.04. I'm building the release on the build server, copying the archive to the webservers and, unarchiving it and starting it there.
When I build my release and try to run it on the webserver I get the following error on startup:
Failed setting -name! The hostname in 'myapp@' is not fully qualified
The documentation linked above states:
The ${HOSTNAME} and ${NODE_COOKIE} parts will only be dynamically replaced at runtime if you export REPLACE_OS_VARS=true in the system environment prior to starting the release, so be sure you do so if you want to use this approach.
Based on that I added REPLACE_OS_VARS=true
to the webserver environment, but it seems to have no affect. I also added it to the environment on the build server out of desperation but got the same results.
Is there anything else that needs to be done other than setting this environment variable to get the dynamic vm.args to work or am I just missing something here?
Here are steps that work. Reproduce, then compare to what you have to find the issue.
mix new config_test && cd config_test
Add {:distillery, "~> 2.0", runtime: false}
as dependency, then run
mix deps.get && mix release.init
Replace -name <%= release_name %>@127.0.0.1
in your vm.args
with
-name <%= release_name %>@${HOSTNAME}
Execute
MIX_ENV=prod mix release
REPLACE_OS_VARS=true HOSTNAME=example.com MIX_ENV=prod _build/prod/rel/config_test/bin/config_test console
Then run Node.self()
in the interactive shell. This prints :"[email protected]"
for me.
Note that HOSTNAME
should be set to an IP or a fully-qualified domain name. For using localhost
or other local name (without a dot), specify -sname
instead of -name
.