kvs_sup.erl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. -module(kvs_sup).
  2. -behaviour(supervisor).
  3. -export([start_link/0, stop_riak/0]).
  4. -export([init/1]).
  5. -define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
  6. start_link() ->
  7. supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  8. stop_riak() ->
  9. application:stop(riak_kv),
  10. application:stop(riak_pipe),
  11. application:stop(eleveldb),
  12. application:stop(erlang_js),
  13. application:stop(webmachine),
  14. application:stop(mochiweb),
  15. application:stop(bitcask).
  16. init([]) ->
  17. RestartStrategy = one_for_one,
  18. MaxRestarts = 1000,
  19. MaxSecondsBetweenRestarts = 3600,
  20. SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
  21. Restart = permanent,
  22. Shutdown = 2000,
  23. Type = worker,
  24. case application:get_env(kvs, riak_srv_node) of
  25. undefined ->
  26. error_logger:info_msg("Waiting for Riak to Start...."),
  27. kvs:start(),
  28. error_logger:info_msg("Waiting for Riak to Initialize....");
  29. {ok, _Value} -> skip end,
  30. kvs:initialize(),
  31. kvs:init_indexes(),
  32. case application:get_env(kvs, riak_srv_node) of
  33. undefined ->
  34. kvs:init_indexes(),
  35. case application:get_env(kvs, sync_nodes) of
  36. true -> [error_logger:info_msg("Joined: ~p ~p~n", [N, riak_core:join(N)]) || N <- application:get_env(kvs, nodes) -- [node()] ];
  37. _ -> skip end,
  38. case application:get_env(kvs, pass_init_db) of true -> pass; _ -> kvs:init_db() end;
  39. _ -> skip end,
  40. {ok, { {one_for_one, 5, 10}, []} }.