Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 72 lines (59 sloc) 2.644 kb
0ddde2b @nniclausse use OTP supervision to handle os_mon_(munin|erlang|snmp) restart on
nniclausse authored
1 %%% Copyright (C) 2009 Nicolas Niclausse
2 %%%
3 %%% This program is free software; you can redistribute it and/or modify
4 %%% it under the terms of the GNU General Public License as published by
5 %%% the Free Software Foundation; either version 2 of the License, or
6 %%% (at your option) any later version.
7 %%%
8 %%% This program is distributed in the hope that it will be useful,
9 %%% but WITHOUT ANY WARRANTY; without even the implied warranty of
10 %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 %%% GNU General Public License for more details.
12 %%%
13 %%% You should have received a copy of the GNU General Public License
14 %%% along with this program; if not, write to the Free Software
15 %%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 %%%
17 %%% In addition, as a special exception, you have the permission to
18 %%% link the code of this program with any library released under
19 %%% the EPL license and distribute linked combinations including
20 %%% the two.
21
22 -module(ts_os_mon_sup).
23 -vc('$Id: ts_client_sup.erl 953 2008-11-23 16:57:05Z nniclausse $ ').
24 -author('nicolas.niclausse@niclux.org').
25
26 -behaviour(supervisor).
27
583ea5e @nniclausse put macros in a separated header file; add NOW macro
nniclausse authored
28 -include("ts_macros.hrl").
0ddde2b @nniclausse use OTP supervision to handle os_mon_(munin|erlang|snmp) restart on
nniclausse authored
29
30 %% External exports
31 -export([start_link/1, start_child/2]).
32
33 %% supervisor callbacks
34 -export([init/1]).
35
36 %%%----------------------------------------------------------------------
37 %%% API
38 %%%----------------------------------------------------------------------
39 start_link(Plugin) ->
40 Module=get_module(Plugin),
41 supervisor:start_link({local,Module}, ?MODULE, [Plugin]).
42
43 start_child(Plugin, Args) ->
44 ?LOGF("Starting child for plugin ~p with args ~p~n",[Plugin,Args], ?DEB),
45 Module=get_module(Plugin),
46 supervisor:start_child(Module,[Args]).
47
48 %%%----------------------------------------------------------------------
49 %%% Callback functions from supervisor
50 %%%----------------------------------------------------------------------
51
52 %%----------------------------------------------------------------------
53 %% Func: init/1
54 %% Returns: {ok, {SupFlags, [ChildSpec]}} |
55 %% ignore |
56 %% {error, Reason}
57 %%----------------------------------------------------------------------
58 init([Plugin]) ->
59 ?LOGF("Starting with args ~p~n",[Plugin], ?INFO),
2ca8923 @nniclausse don't try to connect in the init phase (can be long), do this later
nniclausse authored
60 SupFlags = {simple_one_for_one, 20, 20},
0ddde2b @nniclausse use OTP supervision to handle os_mon_(munin|erlang|snmp) restart on
nniclausse authored
61 {ok, {SupFlags, get_spec(Plugin)}}.
62
63 %% internal funs
64
65 get_spec(Plugin) ->
66 Module=get_module(Plugin),
67 [{Module,{Module, start, []}, permanent, 2000, worker,[Module]}].
68
69 get_module(Plugin) when is_atom(Plugin)->
70 ModuleStr="ts_os_mon_" ++ atom_to_list(Plugin),
71 list_to_atom(ModuleStr).
Something went wrong with that request. Please try again.