2

Background

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.

Problem

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?

  • I've not really messed around too much with vm.args, however, but these docs look like they could help https://github.com/bitwalker/distillery/blob/master/docs/config/runtime.md – Harrison Lucas Apr 19 '19 at 11:44

1 Answers1

2

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 :"config_test@example.com" 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.

Roman Boiko
  • 3,576
  • 1
  • 25
  • 41
  • My guess is that `HOSTNAME` isn't set on the server. – Roman Boiko Apr 23 '19 at 18:23
  • 1
    Seems you're right! I'm running the release using systemd and had the environment variable set in /etc/environment but it doesn't seem be picking it up when it is just in there. Adding it to the .service configuration file seems to have got the nodes running. So thank you for that! I've subsequently run into another related problem, which I have detailed here https://stackoverflow.com/questions/55840974/how-to-get-elixir-nodes-to-connect-automatically-on-startup. If you have any thoughts on that it would be much appreciated. – Josiah Witt Apr 25 '19 at 02:28