I want to run different instances of the same app (not copies of the same app) on the same server (clustering) using different ports, so I used libcluster library and did the following (in application.ex):
def start(_type, _args) do
import Supervisor.Spec
# Define Topologies for clustering
topologies = [
example: [
strategy: Cluster.Strategy.Gossip
]
]
# List all child processes to be supervised
children = [
# For Clustering
{Cluster.Supervisor, [topologies, [name: MyApp.ClusterSupervisor]]},
# Start the endpoint when the application starts
supervisor(MyAppWeb.Endpoint, []),
{ConCache, [name: :my_cache, ttl_check_interval: false]}
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
result = Supervisor.start_link(children, opts)
end
I even tried this:
topologies = [
example: [
strategy: Cluster.Strategy.Gossip,
config: [hosts: [:"a@127.0.0.1", :"b@127.0.0.1",:"b@127.0.0.1",:"d@127.0.0.1"]],
]
]
but when I tried the following on the server (Ubuntu 18):
PORT=3000 elixir --sname a -S mix phx.server
then
PORT=3001 elixir --sname b -S mix phx.server
I get the following error
** (Mix) Could not start application my_app: MyApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: MyAppWeb.Endpoint
** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, MyAppWeb.Endpoint.HTTP}
** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
** (EXIT) {:listen_error, MyAppWeb.Endpoint.HTTP, :eaddrinuse}
what should I do to make it work.