<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>I have similar problem, and didn't find an ultimate solution yet.
My current approach is to register the singleton gen_server using
{via, my_global_module, my_regname(...)} rather than {global,
?MODULE}. In "my_global_module" I control how a conflict is
resolved between running server and a new one. In the "resolve"
callback of global:register_name I'm able to query for each of
gen_server's version and decide which of two gen_server lives and
which is to shut down. This helps also in case of rolling updates.<br>
</p>
<p>Best regards,<br>
Vyacheslav<br>
</p>
<div class="moz-cite-prefix">On 16.12.2021 19:34, Roberto Ostinelli
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAFXp3LLOcj9N8nq50guR3BOnx8AcOb3UFC0LYmjLyazGXNBowQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">Not necessarily. By the time your first gen_server
start you might already have more than one node in your cluster.
<div>I'm ok having other nodes joining later on, I'm trying to
avoid a clash where multiple nodes execute the "cluster init"
code<br>
<div><br>
</div>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Thu, Dec 16, 2021 at 3:48
PM Roger Lipscombe <<a href="mailto:roger@differentpla.net"
moz-do-not-send="true" class="moz-txt-link-freetext">roger@differentpla.net</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Define
"cluster start". In normal operation, there's nothing stopping<br>
another node from joining the cluster at some arbitrary later
time,<br>
even days later. The first node to come up is a degenerate,
single<br>
node cluster, no?<br>
<br>
On Thu, 16 Dec 2021 at 11:00, Roberto Ostinelli <<a
href="mailto:ostinelli@gmail.com" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">ostinelli@gmail.com</a>>
wrote:<br>
><br>
> Dear all,<br>
> I'm trying to run an operation only once on cluster start
but there's clearly something that I'm missing in the global
module (see other related question here [1]).<br>
><br>
> Therefore this time I'm trying to have a single global
gen_server which I start directly from application start/2
callback with:<br>
> gen_server:start_link({global, ?MODULE}, ?MODULE, [],
Options).<br>
><br>
> Nodes are already connected at that point (I can see them
with nodes()), however for some reason this registration works
on all the nodes and I find myself with multiple gen_server
registered globally.<br>
><br>
> What is the proper way to register a global singleton
gen_server at cluster level on application start? mY need is
to run an operation only _once_ a cluster boots up.<br>
><br>
> [1] <a
href="http://erlang.org/pipermail/erlang-questions/2021-December/101781.html"
rel="noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">http://erlang.org/pipermail/erlang-questions/2021-December/101781.html</a><br>
</blockquote>
</div>
</blockquote>
</body>
</html>