mmyers

mmyers

Dynamically connect nodes and start a distributed application

Is it possible to have nodes running independently, and then start running a distributed app with a fail-over/takeover configuration programmatically at run-time?

I’ve been working with the Magic 8-ball example in https://learnyousomeerlang.com/distributed-otp-applications with the A-B-C nodes. I have it working in Elixir, but it requires configuration files that are pre-configured with the distributed node cluster and fail-over rules. I’ve read about libcluster+swarm, but it seems like overkill for my 2-node clusters. And it seems like I would still have to have the nodes pre-configured.

Here’s the idea of what I’m trying to accomplish. Maybe there is an easier/better way to do this, I’m open to ideas:

I will have two nodes that are running on separate IoT devices. At first these nodes don’t know about each other, and they don’t know if they will ever be clustered - they may not be.

The devices will receive a signal (details TBD) informing them that they should connect to each other and start running a distributed application with one node acting as fail-over for the other.

Playing around in iex, it feels like I’m getting closer, but not really.
Note, for this example, both nodes are on my local computer.

iex --name "a@192.168.0.2" -pa _build/dev/lib/m8ball/ebin --cookie cookie_s
iex --name "b@192.168.0.2" -pa _build/dev/lib/m8ball/ebin --cookie cookie_s

Note: Initially the cookies won’t be the same, but a shared cookie will be part of the signal/command to connect.
Devices receive the command to connect and run the distributed m8ball app.

  • Connect the Nodes
    Node.connect(:"b@192.168.0.2")

  • Start the distributed application at a.

:dist_ac.start_link  # It seems like I need to start `dist_ac` (since it's not running on the individual nodes).
:dist_ac.load_application(:m8ball, [{:m8ball, 5000, ['a@192.168.0.2', {'b@192.168.0.2'}]}])

It seem like :dist_ac.load_application is what I need, but it never returns. I’m not sure what I’m missing.
There is not a lot of documentation or articles that I can find about this. I had to look at the Erlang source code to get this far.

Any suggestions?

Marked As Solved

mmyers

mmyers

Thanks for your suggestions anthonator.

Apparently, what I was trying to do is not really possible. If I had kept reading on learnyousomeerlang, I would have seen:

The thing is, for the mechanism to work, the application needs to be started as part of the boot procedure of the node .

Currently I’m going with a simple Node monitor GenServer to detect :nodeup and :nodedown and can easily connect with Node.connect now I’m also looking into Epmdless

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New

We're in Beta

About us Mission Statement