Skip to content

Commit

Permalink
Merge pull request 2600hz#1712 from 2600hz/KAZOO-4613
Browse files Browse the repository at this point in the history
KAZOO-4613: read a release`s cookie from conf, for services or SUP co…
  • Loading branch information
lazedo committed Apr 8, 2016
2 parents 9a79cc2 + 39e9de6 commit 7eabc5e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ELVIS = $(ROOT)/utils/elvis/elvis

KAZOODIRS = core/Makefile applications/Makefile

.PHONY: $(KAZOODIRS) deps core apps xref xref_release dialyze dialyze-apps dialyze-core dialyze-kazoo clean clean-test clean-release build-release tar-release release elvis
.PHONY: $(KAZOODIRS) deps core apps xref xref_release dialyze dialyze-apps dialyze-core dialyze-kazoo clean clean-test clean-release build-release tar-release release read-release-cookie elvis

all: compile rel/dev-vm.args

Expand Down Expand Up @@ -91,6 +91,10 @@ endif
@RELX_REPLACE_OS_VARS=true KZname='-name $(REL)' _rel/kazoo/bin/kazoo $(ACT) "$$@"


read-release-cookie: REL ?= whistle_apps
read-release-cookie:
@RELX_REPLACE_OS_VARS=true KZname='-name $(REL)' _rel/kazoo/bin/kazoo escript lib/whistle_config-*/priv/read-cookie.escript "$$@"

DIALYZER ?= dialyzer
PLT ?= .kazoo.plt
OTP_APPS ?= erts kernel stdlib crypto public_key ssl asn1 inets
Expand Down
21 changes: 21 additions & 0 deletions core/whistle_config/priv/read-cookie.escript
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env escript
%%!
%% -*- coding: utf-8 -*-

%% Reads a running release's cookie from config.ini

-mode('compile').

-export([main/1]).

%% API

main(_) ->
"-name "++Release = os:getenv("KZname"),
REL = list_to_atom(Release),
INI = whistle_config_init:load_file(),
{_, RelEnv} = lists:keyfind(REL, 1, INI),
{_, Cookie} = lists:keyfind('cookie', 1, RelEnv),
io:format("~s\n", [Cookie]).

%% End of Module
22 changes: 14 additions & 8 deletions core/whistle_config/src/whistle_config_init.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
,reload/0
]).

%% To read config.ini
-export([load_file/0]).

%%--------------------------------------------------------------------
%% @public
%% @doc Starts the app for inclusion in a supervisor tree
%%--------------------------------------------------------------------
-spec start_link() -> startlink_ret().
start_link() ->
set_env(),
set_env(),
'ignore'.

ini_file() ->
Expand All @@ -28,28 +31,31 @@ ini_file() ->
File -> File
end.

-spec load_file(string()) -> {'ok', wh_proplist()}.
-spec load_file() -> wh_proplist().
-spec load_file(file:name()) -> wh_proplist().
load_file() ->
load_file(ini_file()).
load_file(File) ->
case zucchini:parse_file(File) of
{'ok', Prop} ->
lager:info("loaded configs from file ~s", [File]),
{'ok', Prop};
Prop;
{'error', 'enoent'} ->
lager:warning("file ~s does not exist or is not accessible", [File]),
lager:warning("please create ~s or set the environment variable ~s to the path of the config file", [File, ?CONFIG_FILE_ENV]),
lager:warning("trying defaults instead"),
{'ok', ?SECTION_DEFAULTS};
?SECTION_DEFAULTS;
{'error', _}=Error ->
lager:warning("error loading file ~s: ~s", [File, Error]),
lager:warning("trying defaults instead"),
{'ok', ?SECTION_DEFAULTS}
?SECTION_DEFAULTS
end.

-spec set_env() -> 'ok'.
set_env() ->
{'ok', X} = load_file(ini_file()),
lager:debug("setting config env ~p", [X]),
application:set_env('whistle_config', 'wh_config', X).
AppEnv = load_file(),
lager:debug("setting config env ~p", [AppEnv]),
application:set_env('whistle_config', 'wh_config', AppEnv).

-spec reload() -> 'ok'.
reload() ->
Expand Down
10 changes: 10 additions & 0 deletions doc/engineering/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,13 @@ When troubleshooting, this attaches a REPL to the running faulty `ecallmgr` node
This gracefully stops an `ecallmgr` node:

REL=ecallmgr ACT=stop make release


### Read a release's cookie from Kazoo's configuration

REL=whistle_apps make read-release-cookie

This hits `/etc/kazoo/config.ini` or the file at `$KAZOO_CONFIG`
and reads the cookie value for release `REL`.

Note: the release does not even need to be started!

0 comments on commit 7eabc5e

Please sign in to comment.