diff --git a/bin/emqx b/bin/emqx index 5f9d0fdc6..6c2cd000e 100755 --- a/bin/emqx +++ b/bin/emqx @@ -341,19 +341,51 @@ relx_gen_id() { od -t x -N 4 /dev/urandom | head -n1 | awk '{print $2}' } +call_nodetool() { + "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$@" +} + # Control a node relx_nodetool() { command="$1"; shift ERL_FLAGS="${ERL_FLAGS:-} $EPMD_ARG" \ - "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ + call_nodetool "$NAME_TYPE" "$NAME" \ -setcookie "$COOKIE" "$command" "$@" } call_hocon() { - "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" hocon "$@" \ + call_nodetool hocon "$@" \ || die "call_hocon_failed: $*" $? } +get_config_value() { + path_to_value="$1" + call_hocon -s "$SCHEMA_MOD" -I "$CONFIGS_DIR/" -c "$RUNNER_ETC_DIR"/emqx.conf get "$path_to_value" | tr -d \" +} + +check_license() { + if [ "$IS_ENTERPRISE" == "no" ]; then + return 0 + fi + + file_license="${EMQX_LICENSE__FILE:-$(get_config_value license.file)}" + + if [[ -n "$file_license" && ("$file_license" != "undefined") ]]; then + call_nodetool check_license_file "$file_license" + else + key_license="${EMQX_LICENSE__KEY:-$(get_config_value license.key)}" + + if [[ -n "$key_license" && ("$key_license" != "undefined") ]]; then + call_nodetool check_license_key "$key_license" + else + echoerr "License not found." + echoerr "Please specify one via EMQX_LICENSE__KEY or EMQX_LICENSE__FILE variables" + echoerr "or via license.key|file in emqx_enterprise.conf." + return 1 + fi + fi +} + # Run an escript in the node's environment relx_escript() { shift; scriptpath="$1"; shift @@ -374,11 +406,6 @@ generate_config() { ## changing the config 'log.rotation.size' rm -rf "${RUNNER_LOG_DIR}"/*.siz - EMQX_LICENSE_CONF_OPTION="" - if [ "${EMQX_LICENSE_CONF:-}" != "" ]; then - EMQX_LICENSE_CONF_OPTION="-c ${EMQX_LICENSE_CONF}" - fi - ## timestamp for each generation local NOW_TIME NOW_TIME="$(call_hocon now_time)" @@ -387,9 +414,7 @@ generate_config() { ## NOTE: the generate command merges environment variables to the base config (emqx.conf), ## but does not include the cluster-override.conf and local-override.conf ## meaning, certain overrides will not be mapped to app.