diff --git a/src/machi_chain_manager1.erl b/src/machi_chain_manager1.erl index ef02f97..9afa807 100644 --- a/src/machi_chain_manager1.erl +++ b/src/machi_chain_manager1.erl @@ -104,6 +104,14 @@ stop(Pid) -> ping(Pid) -> gen_server:call(Pid, {ping}, infinity). +%% @doc Set chain members list. +%% +%% NOTE: This implementation is a bit brittle, in that an author with +%% higher rank may try to re-suggest the old membership list if it +%% races with an author of lower rank. For now, we suggest calling +%% set_chain_members() first on the author of highest rank and finish +%% with lowest rank, i.e. name z* first, name a* last. + set_chain_members(Pid, MembersDict) -> gen_server:call(Pid, {set_chain_members, MembersDict}, infinity). diff --git a/src/machi_flu_psup.erl b/src/machi_flu_psup.erl index 4f9d408..4405bf6 100644 --- a/src/machi_flu_psup.erl +++ b/src/machi_flu_psup.erl @@ -26,7 +26,7 @@ -behaviour(supervisor). %% External API --export([start_flu_package/4, stop_flu_package/1]). +-export([make_package_spec/4, start_flu_package/4, stop_flu_package/1]). %% Internal API -export([start_link/4, make_p_regname/1, make_mgr_supname/1, make_proj_supname/1]). @@ -34,10 +34,13 @@ %% Supervisor callbacks -export([init/1]). +make_package_spec(FluName, TcpPort, DataDir, Props) -> + {FluName, {machi_flu_psup, start_link, + [FluName, TcpPort, DataDir, Props]}, + permanent, 5000, supervisor, []}. + start_flu_package(FluName, TcpPort, DataDir, Props) -> - Spec = {FluName, {machi_flu_psup, start_link, - [FluName, TcpPort, DataDir, Props]}, - permanent, 5000, supervisor, []}, + Spec = make_package_spec(FluName, TcpPort, DataDir, Props), {ok, _SupPid} = supervisor:start_child(machi_flu_sup, Spec). stop_flu_package(FluName) -> diff --git a/src/machi_flu_sup.erl b/src/machi_flu_sup.erl index f74ea07..51efd87 100644 --- a/src/machi_flu_sup.erl +++ b/src/machi_flu_sup.erl @@ -41,5 +41,11 @@ init([]) -> MaxRestarts = 1000, MaxSecondsBetweenRestarts = 3600, SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts}, - {ok, {SupFlags, []}}. + + Ps = application:get_env(machi, initial_flus, []), + FLU_specs = [machi_flu_psup:make_package_spec(FluName, TcpPort, + DataDir, Props) || + {FluName, TcpPort, DataDir, Props} <- Ps], + + {ok, {SupFlags, FLU_specs}}.