Preferred way for phased startup for app

Ken Robinson <>
Sun Nov 21 14:58:44 CET 2010


Hi All,
At the moment I am running an application where I am using a
supervisor with several gen_servers and gen_fsms. Certain servers
require other servers to start and initialize successfully.

Is the order in which I start them the order in which they fact start?
What is the best way to ensure a particular server has initialized correctly?

At the moment I am running the following code at the end of this post.
However I saw in doco for app the concept of start_phases
(http://www.erlang.org/doc/man/app.html). If this is the preferred way
is there any example code anyone can point me to? Many thanks.

    %% I need this things to be up before I can proceed
    {ok, RequiredProcesses} = jaus.util.config:get(requires, Args),
    UpdatedRequiredProcesses = lists:append(RequiredProcesses,
[jaus_core_componentserver]),
    ProcessPidList = [{Elem, erlang:whereis(Elem)} || Elem <-
UpdatedRequiredProcesses ],
    ProcessAliveList = [{ProcessName,
erlang:is_process_alive(ProcessId)} || {ProcessName,  ProcessId} <-
ProcessPidList],
    ProcessNotUpList = [ ProcessName || {ProcessName, ProcessUp} <-
ProcessAliveList, ProcessUp == false],
    case erlang:length(ProcessNotUpList) of
	0 ->
	    %% do nothing
	    log4erl:info("[Src ~p Line ~p] msg - ~p~n", [?FILE, ?LINE,
ProcessNotUpList]);
	_Default ->
	    %% terminate by throwing error
	    log4erl:info("[Src ~p Line ~p] msg Process(s) not up - ~p~n",
[?FILE, ?LINE, ProcessNotUpList]),
	    erlang:error({stop, {process_not_up, ProcessNotUpList}})
    end,

-- 
regards,
Ken Robinson
Mob +61438681120
Home +61738523767
Work +61733063137


More information about the erlang-questions mailing list