Skip to content

Commit

Permalink
Merge pull request #51 from 2600hz/KAZOO-879
Browse files Browse the repository at this point in the history
KAZOO-879: Update sup command to user wh_config library

Looks good, hope it works like you think it does! :)
  • Loading branch information
James Aimonetti committed Jun 6, 2013
2 parents e132eda + da33205 commit e442e54
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions utils/sup/src/sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
-module(sup).

-include_lib("whistle/include/wh_types.hrl").
-include_lib("whistle_config/src/wh_config.erl").

-export([main/1]).

Expand Down Expand Up @@ -85,16 +86,33 @@ get_target(Options, Verbose) ->
-spec get_cookie/2 :: (proplist(), string()) -> 'ok'.
get_cookie(Options, Node) ->
Cookie = case {Node, proplists:get_value(cookie, Options, "")} of
{"whistle_apps", ""} -> get_cookie_from_vmargs(?WHAPPS_VM_ARGS);
{"ecallmgr", ""} -> get_cookie_from_vmargs(?ECALL_VM_ARGS);
{"whistle_apps", ""} -> maybe_get_cookie('whistle_apps');
{"ecallmgr", ""} -> maybe_get_cookie('ecallmgr');
{_, ""} -> print_no_setcookie();
{_, C} -> C
end,
erlang:set_cookie(node(), list_to_atom(Cookie)),
erlang:set_cookie(node(), Cookie),
Cookie.

maybe_get_cookie('whistle_apps') ->
case wh_config:get_atom('whistle_apps', 'cookie') of
[] ->
list_to_atom(get_cookie_from_vmargs(?WHAPPS_VM_ARGS));
[Cookie|_] ->
Cookie
end;
maybe_get_cookie('ecallmgr') ->
case wh_config:get_atom('ecallmgr', 'cookie') of
[] ->
list_to_atom(get_cookie_from_vmargs(?ECALL_VM_ARGS));
[Cookie|_] ->
Cookie
end;
maybe_get_cookie(_) ->
print_no_setcookie().

-spec get_cookie_from_vmargs/1 :: ([string(),...]) -> string().
get_cookie_from_vmargs([]) ->
get_cookie_from_vmargs([]) ->
print_no_setcookie();
get_cookie_from_vmargs([File|Files]) ->
case file:read_file(File) of
Expand Down Expand Up @@ -141,9 +159,9 @@ print_no_setcookie() ->
io:format(standard_io, "Unable to automatically determine cookie~n", []),
io:format(standard_io, "Please provide the cookie of the node you are connecting to~n", []),
io:format(standard_io, "\"./sup -c <cookie>\"~n", []),
halt(1).
halt(1).

-spec print_ping_failed/2 :: (string(), string()) -> no_return().
-spec print_ping_failed/2 :: (string(), string()) -> no_return().
print_ping_failed(Target, Cookie) ->
io:format(standard_io, "Failed to connect to service '~s' with cookie '~s'~n", [Target, Cookie]),
io:format(standard_io, " Possible fixes:~n", []),
Expand All @@ -152,7 +170,7 @@ print_ping_failed(Target, Cookie) ->
io:format(standard_io, " * Verify that the hostname being used is a whistle node~n", []),
halt(1).

-spec print_unresolvable_host/1 :: (string()) -> no_return().
-spec print_unresolvable_host/1 :: (string()) -> no_return().
print_unresolvable_host(Host) ->
io:format(standard_io, "If you can not run \"ping ~s\" then this program will not be able to connect.~n", [Host]),
io:format(standard_io, " Possible fixes:~n", []),
Expand Down

0 comments on commit e442e54

Please sign in to comment.