I tried to run a simple app in a distributed manner to test failover-takeover features but failed.
What I want to:
The application is myapp_api with a rest api, it has myapp application as a dependency. I want to start myapp_api on 3 nodes, I want the whole app (myapp_api + myapp) to be working only at one node at the same time.
What is wrong:
The main app (myapp_api) works as expected: only at one node with failover and takeover. But for some reason depended myapp always starts at every node. I want it to be working only at one node at the same time.
What I do:
My config for the first node as an example.
[
{kernel,
[{distributed, [{myapp_api,
1000,
['n1@myhost', {'n2@myhost', 'n3@myhost'}]}]},
{sync_nodes_optional, ['n2@myhost', 'n3@myhost']},
{sync_nodes_timeout, 5000}
]}
].
I call
erl -sname nI -config nI.config -pa apps/*/ebin deps/*/ebin -s myapp_api at every node.
Now this gets a bit confusing because you say:
and you add:
In the first paragraph you say
myapp_apishould run everywhere, on the second quote you say it works as intended by booting on one node at a time.I'll be assuming here that you want the whole set-up to be a failover, not just the top-level app and I just got confused on the first paragraph.
The config file you use shows what happens:
The important bit is that
myapp_apihas the nodes['n1@myhost', {'n2@myhost', 'n3@myhost'}]defined. This order means it runs onn1@myhostin top priority, and then on the other nodes with equal priority if there is a failover.The thing is that none of the dependencies are distributed in the same way, and can therefore be expected to be running everywhere.
You should only need to expand on that config file to get it to work. Here I've done it and reindented it to show its structure better:
I haven't tested it directly, but I'm pretty sure this will work.
If what you wanted was for
myapp_apito be everywhere but formyappto run in one place, you could use global registration, give a name tomyapp's public-facing process, getmyapp_apito call these.myapp_apiwould then be able to route traffic to wherevermyappis when supported with the following config:(See how
myappis the only app getting a distribution profile? Other apps will get to run on all nodes)