1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
%% AB. All Rights Reserved.''
16
%% $Id: mnesia_sup.erl,v 1.1 2008/12/17 09:53:39 mikpe Exp $
18
%% Supervisor for the entire Mnesia application
22
-behaviour(application).
23
-behaviour(supervisor).
25
-export([start/0, start/2, init/1, stop/1, start_event/0, kill/0]).
27
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28
%% application and suprvisor callback functions
30
start(normal, Args) ->
31
SupName = {local,?MODULE},
32
case supervisor:start_link(SupName, ?MODULE, [Args]) of
34
{ok, Pid, {normal, Args}};
42
SupName = {local,?MODULE},
43
supervisor:start_link(SupName, ?MODULE, []).
48
init([]) -> % Supervisor
50
init([[]]) -> % Application
53
{error, {badarg, BadArg}}.
56
Flags = {one_for_all, 0, 3600}, % Should be rest_for_one policy
58
Event = event_procs(),
59
Kernel = kernel_procs(),
60
Mnemosyne = mnemosyne_procs(),
62
{ok, {Flags, Event ++ Kernel ++ Mnemosyne}}.
65
KillAfter = timer:seconds(30),
66
KA = mnesia_kernel_sup:supervisor_timeout(KillAfter),
68
[{E, {?MODULE, start_event, []}, permanent, KA, worker, [E, gen_event]}].
71
K = mnesia_kernel_sup,
73
[{K, {K, start, []}, permanent, KA, supervisor, [K, supervisor]}].
76
case mnesia_monitor:get_env(embedded_mnemosyne) of
80
[{Q, {Q, start, []}, permanent, KA, supervisor, [Q, supervisor]}];
85
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89
case gen_event:start_link({local, mnesia_event}) of
91
case add_event_handler() of
101
add_event_handler() ->
102
Handler = mnesia_monitor:get_env(event_module),
103
gen_event:add_handler(mnesia_event, Handler, []).
105
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109
Mnesia = [mnesia_fallback | mnesia:ms()],
110
Mnemosyne = mnemosyne_ms(),
111
Kill = fun(Name) -> catch exit(whereis(Name), kill) end,
112
lists:foreach(Kill, Mnemosyne),
113
lists:foreach(Kill, Mnesia),
114
lists:foreach(fun ensure_dead/1, Mnemosyne),
115
lists:foreach(fun ensure_dead/1, Mnesia),
117
case lists:keymember(mnesia, 1, application:which_applications()) of
123
case whereis(Name) of
133
case mnesia_monitor:get_env(embedded_mnemosyne) of
134
true -> mnemosyne:ms();