Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 151 lines (131 sloc) 5.267 kb
21abc5b Claes Wikstrom Initial revision
authored
1 %%%----------------------------------------------------------------------
2 %%% File : yaws_sup.erl
3 %%% Author : Claes Wikstrom <klacke@bluetail.com>
455578a Steve Vinoski major trailing whitespace cleanup
vinoski authored
4 %%% Purpose :
21abc5b Claes Wikstrom Initial revision
authored
5 %%% Created : 16 Jan 2002 by Claes Wikstrom <klacke@bluetail.com>
6 %%%----------------------------------------------------------------------
7
8 -module(yaws_sup).
9 -author('klacke@bluetail.com').
31fdaae Claes Wikstrom pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail.co...
authored
10 -include("../include/yaws.hrl").
21abc5b Claes Wikstrom Initial revision
authored
11
12 -behaviour(supervisor).
13
14 %% External exports
15 -export([start_link/0]).
16
17 %% supervisor callbacks
18 -export([init/1]).
6b26557 Steve Vinoski improved embedded support
vinoski authored
19 -export([get_app_args/0, child_specs/0]).
9624397 Claes Wikstrom patch from Fredrik Linder to make it easier to integrate yaws into apps...
authored
20
21 -import(lists, [member/2]).
21abc5b Claes Wikstrom Initial revision
authored
22
23 %%%----------------------------------------------------------------------
24 %%% API
25 %%%----------------------------------------------------------------------
26 start_link() ->
27 supervisor:start_link({local, ?MODULE}, ?MODULE, []).
28
29 %%%----------------------------------------------------------------------
30 %%% Callback functions from supervisor
31 %%%----------------------------------------------------------------------
32
33 %%----------------------------------------------------------------------
34 %%----------------------------------------------------------------------
35 init([]) ->
80771c8 Claes Wikstrom cache_refresh to 0 if debug, added a cookie_session-server for persistan...
authored
36
6b26557 Steve Vinoski improved embedded support
vinoski authored
37 ChildSpecs = child_specs(),
38
455578a Steve Vinoski major trailing whitespace cleanup
vinoski authored
39 %% The idea behind this is if we're running in an embedded env,
6b26557 Steve Vinoski improved embedded support
vinoski authored
40 %% typically the supervisor above us wants to control the restarts.
455578a Steve Vinoski major trailing whitespace cleanup
vinoski authored
41 %%
6b26557 Steve Vinoski improved embedded support
vinoski authored
42 %% If we're running standalone --heart can restart the entire node
43 %% If heart is not used, we die.
44 %% 0, 1 means that we never want supervisor restarts
45 {ok,{{one_for_all, 0, 1}, ChildSpecs}}.
46
47 %%----------------------------------------------------------------------
48 %%----------------------------------------------------------------------
49 child_specs() ->
21abc5b Claes Wikstrom Initial revision
authored
50 YawsLog = {yaws_log, {yaws_log, start_link, []},
0be3c7e Claes Wikstrom untabified all of yaws
authored
51 permanent, 5000, worker, [yaws_log]},
21abc5b Claes Wikstrom Initial revision
authored
52
4bead70 Claes Wikstrom The supervisor args were wrong, yaws shall have 1,0 restart strategy
authored
53 YawsServArgs = [_Env = get_app_args()],
9624397 Claes Wikstrom patch from Fredrik Linder to make it easier to integrate yaws into apps...
authored
54 YawsServ = {yaws_server, {yaws_server, start_link, YawsServArgs},
c075573 Christopher Faulet soft yaws shutdown (capflam)
capflam authored
55 permanent, 120000, worker, [yaws_server]},
21abc5b Claes Wikstrom Initial revision
authored
56
6b26557 Steve Vinoski improved embedded support
vinoski authored
57 %% and this guy will restart auxiliary procs that can fail
a0d2c83 Claes Wikstrom added one_for_one supervisor
authored
58 Sup = {yaws_sup_restarts,
59 {yaws_sup_restarts, start_link, []},
60 transient, infinity, supervisor, [yaws_sup_restarts]},
12471ad Claes Wikstrom added configure support for sendfile
authored
61
6b26557 Steve Vinoski improved embedded support
vinoski authored
62 [YawsLog, YawsServ, Sup].
9624397 Claes Wikstrom patch from Fredrik Linder to make it easier to integrate yaws into apps...
authored
63
64 %%----------------------------------------------------------------------
65 %%----------------------------------------------------------------------
66 get_app_args() ->
67 AS=init:get_arguments(),
68 Debug = case application:get_env(yaws, debug) of
0be3c7e Claes Wikstrom untabified all of yaws
authored
69 undefined ->
70 member({yaws, ["debug"]}, AS);
71 {ok, Val} ->
72 Val
73 end,
9624397 Claes Wikstrom patch from Fredrik Linder to make it easier to integrate yaws into apps...
authored
74 Trace = case application:get_env(yaws, trace) of
0be3c7e Claes Wikstrom untabified all of yaws
authored
75 undefined ->
76 case {member({yaws, ["trace", "http"]}, AS),
77 member({yaws, ["trace", "traffic"]}, AS)} of
78 {true, _} ->
79 {true, http};
80 {_, true} ->
81 {true, traffic};
82 _ ->
83 false
84 end;
85 {ok, http} ->
86 {true, http};
87 {ok, traffic} ->
88 {true, traffic};
89 _ ->
90 false
91 end,
9624397 Claes Wikstrom patch from Fredrik Linder to make it easier to integrate yaws into apps...
authored
92 TraceOutput = case application:get_env(yaws, traceoutput) of
0be3c7e Claes Wikstrom untabified all of yaws
authored
93 undefined ->
94 member({yaws, ["traceoutput"]}, AS);
95 {ok, Val3} ->
96 Val3
97 end,
9624397 Claes Wikstrom patch from Fredrik Linder to make it easier to integrate yaws into apps...
authored
98 Conf = case application:get_env(yaws, conf) of
0be3c7e Claes Wikstrom untabified all of yaws
authored
99 undefined ->
100 find_c(AS);
101 {ok, File} ->
102 {file, File}
103 end,
9624397 Claes Wikstrom patch from Fredrik Linder to make it easier to integrate yaws into apps...
authored
104 RunMod = case application:get_env(yaws, runmod) of
0be3c7e Claes Wikstrom untabified all of yaws
authored
105 undefined ->
106 find_runmod(AS);
107 {ok,Mod} ->
108 {ok,Mod}
109 end,
9624397 Claes Wikstrom patch from Fredrik Linder to make it easier to integrate yaws into apps...
authored
110 Embedded = case application:get_env(yaws, embedded) of
0be3c7e Claes Wikstrom untabified all of yaws
authored
111 undefined ->
112 false;
113 {ok, Emb} ->
114 Emb
115 end,
92bafb4 Claes Wikstrom removed the ability change userid, also stopped writing to /tmp/yaws and...
authored
116 Id = case application:get_env(yaws, id) of
0be3c7e Claes Wikstrom untabified all of yaws
authored
117 undefined ->
118 "default";
d63642e Steve Vinoski do not pass the --id option if the default id is used
vinoski authored
119 {ok, Id0} when is_atom(Id0) ->
120 atom_to_list(Id0);
0be3c7e Claes Wikstrom untabified all of yaws
authored
121 {ok, Id0} ->
122 Id0
123 end,
92bafb4 Claes Wikstrom removed the ability change userid, also stopped writing to /tmp/yaws and...
authored
124
455578a Steve Vinoski major trailing whitespace cleanup
vinoski authored
125 #env{debug = Debug, trace = Trace,
126 traceoutput = TraceOutput, conf = Conf,
0be3c7e Claes Wikstrom untabified all of yaws
authored
127 runmod = RunMod, embedded = Embedded, id = Id}.
9624397 Claes Wikstrom patch from Fredrik Linder to make it easier to integrate yaws into apps...
authored
128
129 %%----------------------------------------------------------------------
130 %%----------------------------------------------------------------------
131 find_c([{conf, [File]} |_]) ->
132 {file, File};
133 find_c([_|T]) ->
134 find_c(T);
135 find_c([]) ->
136 false.
137
138 %%----------------------------------------------------------------------
139 %%----------------------------------------------------------------------
140 find_runmod([{runmod, [Mod]} |_]) ->
141 {ok,l2a(Mod)};
142 find_runmod([_|T]) ->
143 find_runmod(T);
144 find_runmod([]) ->
145 false.
146
147 %%----------------------------------------------------------------------
148 %%----------------------------------------------------------------------
f44be6a Claes Wikstrom all calls to old deprecated guard tests removed
authored
149 l2a(L) when is_list(L) -> list_to_atom(L);
150 l2a(A) when is_atom(A) -> A.
Something went wrong with that request. Please try again.