Merge pull request #5000 from zmstone/generate-config-from-node-tool

refactor(bin/emqx): invoke hocon_cli from nodetool
This commit is contained in:
Zaiming (Stone) Shi 2021-06-15 14:43:50 +02:00 committed by GitHub
commit e010aa44b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 15 deletions

View File

@ -27,6 +27,15 @@ mkdir -p "$CONFIGS_DIR"
# hocon try to read environment variables starting with "EMQX_" # hocon try to read environment variables starting with "EMQX_"
export HOCON_ENV_OVERRIDE_PREFIX='EMQX_' export HOCON_ENV_OVERRIDE_PREFIX='EMQX_'
export ROOTDIR="$RUNNER_ROOT_DIR"
export ERTS_DIR="$ROOTDIR/erts-$ERTS_VSN"
export BINDIR="$ERTS_DIR/bin"
export EMU="beam"
export PROGNAME="erl"
export LD_LIBRARY_PATH="$ERTS_DIR/lib:$LD_LIBRARY_PATH"
export ERTS_LIB_DIR="$ERTS_DIR/../lib"
MNESIA_DATA_DIR="$RUNNER_DATA_DIR/mnesia/$NAME"
relx_usage() { relx_usage() {
command="$1" command="$1"
@ -183,6 +192,12 @@ relx_nodetool() {
-setcookie "$COOKIE" "$command" "$@" -setcookie "$COOKIE" "$command" "$@"
} }
call_hocon() {
export RUNNER_ROOT_DIR
export REL_VSN
"$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" hocon "$@"
}
# Run an escript in the node's environment # Run an escript in the node's environment
relx_escript() { relx_escript() {
shift; scriptpath="$1"; shift shift; scriptpath="$1"; shift
@ -210,12 +225,12 @@ generate_config() {
## timestamp for each generation ## timestamp for each generation
local NOW_TIME local NOW_TIME
NOW_TIME="$("$ERTS_PATH"/escript "$RUNNER_ROOT_DIR"/bin/hocon now_time)" NOW_TIME="$(call_hocon now_time)"
## ths command populates two files: app.<time>.config and vm.<time>.args ## ths command populates two files: app.<time>.config and vm.<time>.args
## disable SC2086 to allow EMQX_LICENSE_CONF_OPTION to split ## disable SC2086 to allow EMQX_LICENSE_CONF_OPTION to split
# shellcheck disable=SC2086 # shellcheck disable=SC2086
"$ERTS_PATH"/escript "$RUNNER_ROOT_DIR"/bin/hocon -t "$NOW_TIME" -s emqx_schema -c "$RUNNER_ETC_DIR"/emqx.conf $EMQX_LICENSE_CONF_OPTION -d "$RUNNER_DATA_DIR"/configs generate call_hocon -t "$NOW_TIME" -s emqx_schema -c "$RUNNER_ETC_DIR"/emqx.conf $EMQX_LICENSE_CONF_OPTION -d "$RUNNER_DATA_DIR"/configs generate
## filenames are per-hocon convention ## filenames are per-hocon convention
local CONF_FILE="$CONFIGS_DIR/app.$NOW_TIME.config" local CONF_FILE="$CONFIGS_DIR/app.$NOW_TIME.config"
@ -306,7 +321,7 @@ if [ -z "$NAME_ARG" ]; then
else else
# for boot commands, inspect emqx.conf for node name # for boot commands, inspect emqx.conf for node name
# todo: use get command from hocon escript # todo: use get command from hocon escript
NODENAME="$("$ERTS_PATH"/escript "$RUNNER_ROOT_DIR"/bin/hocon -s emqx_schema -c "$RUNNER_ETC_DIR"/emqx.conf get node.name | tr -d \")" NODENAME="$(call_hocon -s emqx_schema -c "$RUNNER_ETC_DIR"/emqx.conf get node.name | tr -d \")"
fi fi
fi fi
if [ -z "$NODENAME" ]; then if [ -z "$NODENAME" ]; then
@ -332,7 +347,7 @@ PIPE_DIR="${PIPE_DIR:-/$RUNNER_DATA_DIR/${WHOAMI}_erl_pipes/$NAME/}"
COOKIE="${EMQX_NODE_COOKIE:-}" COOKIE="${EMQX_NODE_COOKIE:-}"
if [ -z "$COOKIE" ]; then if [ -z "$COOKIE" ]; then
if [ "$IS_BOOT_COMMAND" = 'yes' ]; then if [ "$IS_BOOT_COMMAND" = 'yes' ]; then
COOKIE="$("$ERTS_PATH"/escript "$RUNNER_ROOT_DIR"/bin/hocon -s emqx_schema -c "$RUNNER_ETC_DIR"/emqx.conf get node.cookie | tr -d \")" COOKIE="$(call_hocon -s emqx_schema -c "$RUNNER_ETC_DIR"/emqx.conf get node.cookie | tr -d \")"
else else
# shellcheck disable=SC2012,SC2086 # shellcheck disable=SC2012,SC2086
LATEST_VM_ARGS="$(ls -t $CONFIGS_DIR/vm.*.args | head -1)" LATEST_VM_ARGS="$(ls -t $CONFIGS_DIR/vm.*.args | head -1)"
@ -357,15 +372,6 @@ else
PROTO_DIST_ARG="-proto_dist $PROTO_DIST" PROTO_DIST_ARG="-proto_dist $PROTO_DIST"
fi fi
export ROOTDIR="$RUNNER_ROOT_DIR"
export ERTS_DIR="$ROOTDIR/erts-$ERTS_VSN"
export BINDIR="$ERTS_DIR/bin"
export EMU="beam"
export PROGNAME="erl"
export LD_LIBRARY_PATH="$ERTS_DIR/lib:$LD_LIBRARY_PATH"
export ERTS_LIB_DIR="$ERTS_DIR/../lib"
MNESIA_DATA_DIR="$RUNNER_DATA_DIR/mnesia/$NAME"
cd "$ROOTDIR" cd "$ROOTDIR"
# User can specify an sname without @hostname # User can specify an sname without @hostname

View File

@ -20,6 +20,15 @@ main(Args) ->
end end
end, end,
ok = add_libs_dir(), ok = add_libs_dir(),
case Args of
["hocon" | Rest] ->
%% forward the call to hocon_cli
hocon_cli:main(Rest);
_ ->
do(Args)
end.
do(Args) ->
ok = do_with_halt(Args, "mnesia_dir", fun create_mnesia_dir/2), ok = do_with_halt(Args, "mnesia_dir", fun create_mnesia_dir/2),
ok = do_with_halt(Args, "chkconfig", fun("-config", X) -> chkconfig(X) end), ok = do_with_halt(Args, "chkconfig", fun("-config", X) -> chkconfig(X) end),
ok = do_with_halt(Args, "chkconfig", fun chkconfig/1), ok = do_with_halt(Args, "chkconfig", fun chkconfig/1),

View File

@ -341,8 +341,6 @@ relx_overlay(ReleaseType) ->
, {template, "bin/emqx_ctl.cmd", "bin/emqx_ctl.cmd"} , {template, "bin/emqx_ctl.cmd", "bin/emqx_ctl.cmd"}
, {copy, "bin/nodetool", "bin/nodetool"} , {copy, "bin/nodetool", "bin/nodetool"}
, {copy, "bin/nodetool", "bin/nodetool-{{release_version}}"} , {copy, "bin/nodetool", "bin/nodetool-{{release_version}}"}
, {copy, "_build/default/lib/hocon/hocon", "bin/hocon"}
, {copy, "_build/default/lib/hocon/hocon", "bin/hocon-{{release_version}}"}
] ++ case is_enterprise() of ] ++ case is_enterprise() of
true -> ee_etc_overlay(ReleaseType); true -> ee_etc_overlay(ReleaseType);
false -> etc_overlay(ReleaseType) false -> etc_overlay(ReleaseType)