Add ability to start FLUs at application startup

This commit is contained in:
Scott Lystig Fritchie 2015-05-07 18:39:39 +09:00
parent 517941aaaa
commit 14fc37bd0d
3 changed files with 22 additions and 5 deletions

View file

@ -104,6 +104,14 @@ stop(Pid) ->
ping(Pid) -> ping(Pid) ->
gen_server:call(Pid, {ping}, infinity). 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) -> set_chain_members(Pid, MembersDict) ->
gen_server:call(Pid, {set_chain_members, MembersDict}, infinity). gen_server:call(Pid, {set_chain_members, MembersDict}, infinity).

View file

@ -26,7 +26,7 @@
-behaviour(supervisor). -behaviour(supervisor).
%% External API %% 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 %% Internal API
-export([start_link/4, -export([start_link/4,
make_p_regname/1, make_mgr_supname/1, make_proj_supname/1]). make_p_regname/1, make_mgr_supname/1, make_proj_supname/1]).
@ -34,10 +34,13 @@
%% Supervisor callbacks %% Supervisor callbacks
-export([init/1]). -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) -> start_flu_package(FluName, TcpPort, DataDir, Props) ->
Spec = {FluName, {machi_flu_psup, start_link, Spec = make_package_spec(FluName, TcpPort, DataDir, Props),
[FluName, TcpPort, DataDir, Props]},
permanent, 5000, supervisor, []},
{ok, _SupPid} = supervisor:start_child(machi_flu_sup, Spec). {ok, _SupPid} = supervisor:start_child(machi_flu_sup, Spec).
stop_flu_package(FluName) -> stop_flu_package(FluName) ->

View file

@ -41,5 +41,11 @@ init([]) ->
MaxRestarts = 1000, MaxRestarts = 1000,
MaxSecondsBetweenRestarts = 3600, MaxSecondsBetweenRestarts = 3600,
SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts}, 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}}.