SNAPKITTYWEST commited on
Commit
894656d
·
verified ·
1 Parent(s): 416d5af

Add src/hyperkitty_sup.erl

Browse files
Files changed (1) hide show
  1. src/hyperkitty_sup.erl +74 -0
src/hyperkitty_sup.erl ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ %%%-------------------------------------------------------------------
2
+ %%% @doc HK-CORE :: root supervisor.
3
+ %%%
4
+ %%% Implements the `<otp_architecture>' hierarchy exactly:
5
+ %%%
6
+ %%% hyperkitty_sup
7
+ %%% +-- hk_event_sup (started first: everything else can publish immediately)
8
+ %%% +-- hk_messaging_sup
9
+ %%% +-- hk_browser_sup
10
+ %%% +-- hk_agent_sup
11
+ %%% +-- hk_search_sup
12
+ %%% +-- hk_api_sup (started after every plane it exposes)
13
+ %%% +-- hk_frontend_sup
14
+ %%%
15
+ %%% `rest_for_one': if an earlier-listed subsystem crashes, every
16
+ %%% subsystem *after* it in this list is restarted too, because they
17
+ %%% may depend on it (e.g. `hk_api_sup' talks to all of `hk_browser_sup',
18
+ %%% `hk_agent_sup', `hk_search_sup', `hk_messaging_sup', and
19
+ %%% `hk_event_sup'; if `hk_event_sup' restarts, callers that publish
20
+ %%% events don't get an error, but every listener that had subscribed
21
+ %%% to the old `hk_event_bus' has silently lost that subscription and
22
+ %%% must resubscribe -- `hk_api_sup' restarting alongside it forces
23
+ %%% every open WebSocket to reconnect and pick that back up, rather
24
+ %%% than leaving the frontend silently stale). Subsystems listed
25
+ %%% *before* the one that crashed are left running, so a browser
26
+ %%% crash never disturbs messaging or the event log, and an agent
27
+ %%% crash never disturbs the browser plane.
28
+ %%%
29
+ %%% `intensity'/`period' are a modest bump over OTP's typical default
30
+ %%% (3/5) to 8/10. The real defense against a mid-tree supervisor's
31
+ %%% *nested* children not having released their registered names yet
32
+ %%% (see `hk_sup_util' -- every registered-name `start_link/0' in
33
+ %%% this application waits for the old holder to actually die and
34
+ %%% retries once, rather than surfacing that transient race as a
35
+ %%% start error) lives in `hk_sup_util:start_link_retry/1', not in
36
+ %%% this number; this headroom just tolerates the occasional
37
+ %%% legitimate extra restart without weakening the check's real
38
+ %%% purpose of catching a genuinely crash-looping child.
39
+ %%% @end
40
+ %%%-------------------------------------------------------------------
41
+ -module(hyperkitty_sup).
42
+ -behaviour(supervisor).
43
+
44
+ -export([start_link/0]).
45
+ -export([init/1]).
46
+
47
+ -define(SERVER, ?MODULE).
48
+
49
+ start_link() ->
50
+ supervisor:start_link({local, ?SERVER}, ?MODULE, []).
51
+
52
+ init([]) ->
53
+ SupFlags = #{strategy => rest_for_one, intensity => 8, period => 10},
54
+ ChildSpecs = [
55
+ sup_child(hk_event_sup),
56
+ sup_child(hk_messaging_sup),
57
+ sup_child(hk_browser_sup),
58
+ sup_child(hk_agent_sup),
59
+ sup_child(hk_search_sup),
60
+ worker_child(hk_health),
61
+ sup_child(hk_api_sup),
62
+ sup_child(hk_frontend_sup)
63
+ ],
64
+ {ok, {SupFlags, ChildSpecs}}.
65
+
66
+ %%% internal
67
+
68
+ sup_child(Mod) ->
69
+ #{id => Mod, start => {Mod, start_link, []}, restart => permanent,
70
+ shutdown => infinity, type => supervisor, modules => [Mod]}.
71
+
72
+ worker_child(Mod) ->
73
+ #{id => Mod, start => {Mod, start_link, []}, restart => permanent,
74
+ shutdown => 5000, type => worker, modules => [Mod]}.