feat: bin/emqx start_iex works

This commit is contained in:
x1001100011 2021-09-14 00:06:16 -07:00
parent 5e812a1add
commit 13e146d1ee
9 changed files with 160 additions and 115 deletions

View File

@ -19,7 +19,7 @@ defmodule EMQX.MixProject do
def application do
[
mod: {:emqx_app, []},
extra_applications: [:logger, :os_mon, :syntax_tools]
extra_applications: [:logger, :os_mon, :syntax_tools, :mnesia]
]
end
@ -29,12 +29,13 @@ defmodule EMQX.MixProject do
{:recon, "~> 2.5"},
{:cowboy, github: "emqx/cowboy", tag: "2.8.2"},
{:esockd, github: "emqx/esockd", tag: "5.8.0"},
{:ekka, github: "emqx/ekka", tag: "0.10.2"},
{:ekka, github: "emqx/ekka", tag: "0.10.8"},
{:gen_rpc, github: "emqx/gen_rpc", tag: "2.5.1"},
{:cuttlefish, github: "emqx/cuttlefish", tag: "v4.0.1"},
{:hocon, github: "emqx/hocon"},
{:pbkdf2, github: "emqx/erlang-pbkdf2", tag: "2.0.4"},
{:snabbkaffe, github: "kafka4beam/snabbkaffe", tag: "0.14.0"}
{:snabbkaffe, github: "kafka4beam/snabbkaffe", tag: "0.14.0"},
{:jiffy, github: "emqx/jiffy", tag: "1.0.5"}
]
end
end

View File

@ -48,6 +48,7 @@
start(_Type, _Args) ->
ok = maybe_load_config(),
%% Load application first for ekka_mnesia scanner
mnesia:change_table_copy_type(schema, node(), disc_copies),
ekka:start(),
ok = ekka_rlog:wait_for_shards(?EMQX_SHARDS, infinity),
ok = maybe_start_quicer(),

View File

@ -1,63 +1,63 @@
authorization {
sources = [
# {
# type: http
# url: "https://emqx.com"
# headers: {
# Accept: "application/json"
# Content-Type: "application/json"
# }
# },
# {
# type: mysql
# server: "127.0.0.1:3306"
# database: mqtt
# pool_size: 1
# username: root
# password: public
# auto_reconnect: true
# ssl: {
# enable: true
# cacertfile: "{{ platform_etc_dir }}/certs/cacert.pem"
# certfile: "{{ platform_etc_dir }}/certs/client-cert.pem"
# keyfile: "{{ platform_etc_dir }}/certs/client-key.pem"
# }
# query: "select ipaddress, username, clientid, action, permission, topic from mqtt_authz where ipaddr = '%a' or username = '%u' or clientid = '%c'"
# },
# {
# type: pgsql
# server: "127.0.0.1:5432"
# database: mqtt
# pool_size: 1
# username: root
# password: public
# auto_reconnect: true
# ssl: {enable: false}
# query: "select ipaddress, username, clientid, action, permission, topic from mqtt_authz where ipaddr = '%a' or username = '%u' or username = '$all' or clientid = '%c'"
# },
# {
# type: redis
# server: "127.0.0.1:6379"
# database: 0
# pool_size: 1
# password: public
# auto_reconnect: true
# ssl: {enable: false}
# cmd: "HGETALL mqtt_authz:%u"
# },
# {
# type: mongo
# mongo_type: single
# server: "127.0.0.1:27017"
# pool_size: 1
# database: mqtt
# ssl: {enable: false}
# collection: mqtt_authz
# selector: { "$or": [ { "username": "%u" }, { "clientid": "%c" } ] }
# },
{
type: file
path: "{{ platform_etc_dir }}/acl.conf"
}
]
# sources = [
# # {
# # type: http
# # url: "https://emqx.com"
# # headers: {
# # Accept: "application/json"
# # Content-Type: "application/json"
# # }
# # },
# # {
# # type: mysql
# # server: "127.0.0.1:3306"
# # database: mqtt
# # pool_size: 1
# # username: root
# # password: public
# # auto_reconnect: true
# # ssl: {
# # enable: true
# # cacertfile: "{{ platform_etc_dir }}/certs/cacert.pem"
# # certfile: "{{ platform_etc_dir }}/certs/client-cert.pem"
# # keyfile: "{{ platform_etc_dir }}/certs/client-key.pem"
# # }
# # query: "select ipaddress, username, clientid, action, permission, topic from mqtt_authz where ipaddr = '%a' or username = '%u' or clientid = '%c'"
# # },
# # {
# # type: pgsql
# # server: "127.0.0.1:5432"
# # database: mqtt
# # pool_size: 1
# # username: root
# # password: public
# # auto_reconnect: true
# # ssl: {enable: false}
# # query: "select ipaddress, username, clientid, action, permission, topic from mqtt_authz where ipaddr = '%a' or username = '%u' or username = '$all' or clientid = '%c'"
# # },
# # {
# # type: redis
# # server: "127.0.0.1:6379"
# # database: 0
# # pool_size: 1
# # password: public
# # auto_reconnect: true
# # ssl: {enable: false}
# # cmd: "HGETALL mqtt_authz:%u"
# # },
# # {
# # type: mongo
# # mongo_type: single
# # server: "127.0.0.1:27017"
# # pool_size: 1
# # database: mqtt
# # ssl: {enable: false}
# # collection: mqtt_authz
# # selector: { "$or": [ { "username": "%u" }, { "clientid": "%c" } ] }
# # },
# {
# type: file
# path: "{{ platform_etc_dir }}/acl.conf"
# }
# ]
}

View File

@ -27,7 +27,7 @@ defmodule EMQXDashboard.MixProject do
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
{:minirest, github: "emqx/minirest", tag: "1.1.7"}
{:minirest, github: "emqx/minirest", tag: "1.2.2"}
]
end
end

View File

@ -27,9 +27,9 @@ defmodule EMQXManagement.MixProject do
defp deps do
[
{:emqx_rule_engine, in_umbrella: true},
{:ekka, github: "emqx/ekka", tag: "0.10.2"},
{:ekka, github: "emqx/ekka", tag: "0.10.8"},
{:emqx_http_lib, github: "emqx/emqx_http_lib", tag: "0.2.1"},
{:minirest, github: "emqx/minirest", tag: "1.1.7"}
{:minirest, github: "emqx/minirest", tag: "1.2.2"}
]
end
end

View File

@ -34,6 +34,10 @@ defmodule EmqxReleaseHelper.Applications do
application :emqx_gateway do
start_type :permanent
overlay do
copy "src/lwm2m/lwm2m_xml", "etc/lwm2m_xml"
end
end
application :emqx_connector do
@ -52,11 +56,6 @@ defmodule EmqxReleaseHelper.Applications do
start_type :permanent
end
application :emqx_data_bridge do
start_type :permanent
overlay :application
end
application :emqx_authn do
start_type :permanent
overlay :application
@ -65,6 +64,10 @@ defmodule EmqxReleaseHelper.Applications do
application :emqx_authz do
start_type :permanent
overlay :application
overlay do
template "etc/acl.conf", "etc/acl.conf"
end
end
application :emqx_dashboard do

View File

@ -28,7 +28,7 @@ defmodule EMQXRuleEngine.MixProject do
[
{:emqx, in_umbrella: true, runtime: false},
{:emqx_http_lib, github: "emqx/emqx_http_lib", tag: "0.2.1"},
{:ekka, github: "emqx/ekka", tag: "0.10.2"}
{:ekka, github: "emqx/ekka", tag: "0.10.8"}
]
end
end

View File

@ -2,12 +2,12 @@
"bbmustache": {:hex, :bbmustache, "1.12.1", "857fbdf86bda46d07201b0e7a969820cb763a7c174c485fd0780d7e033efe9f0", [:rebar3], [], "hexpm", "f4320778c31a821a2a664db8894618abb79c1af7bbf7c03c703c8868d9bb09fe"},
"bcrypt": {:git, "https://github.com/emqx/erlang-bcrypt.git", "dc2ba66acf2332c111362d01137746eefecc5e90", [tag: "0.6.0"]},
"cowboy": {:git, "https://github.com/emqx/cowboy.git", "b89d4689a04149b1a4a3641280aa5c5643f921b2", [tag: "2.8.2"]},
"cowboy_swagger": {:git, "https://github.com/inaka/cowboy_swagger", "f779ffe1365f474f0b569c9cd87ded2ac147a67e", [tag: "2.3.0"]},
"cowboy_swagger": {:git, "https://github.com/inaka/cowboy_swagger", "f4b49a4f289a9ee9ae1ff35772c4e191b5fafbd5", [tag: "2.4.0"]},
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
"cuttlefish": {:git, "https://github.com/emqx/cuttlefish.git", "1b95e3aa275fc240dd51f53e771566b1f89b5fcc", []},
"ecpool": {:git, "https://github.com/emqx/ecpool.git", "0516d2cebd14654ef8c583c347e4a0b01363b86d", [tag: "0.5.1"]},
"eetcd": {:hex, :eetcd, "0.3.4", "27e8b4775230c53a9ef602f62a1603591302b40b2eb195d567edffb35b6cf1a2", [:rebar3], [{:gun, "1.3.3", [hex: :gun, repo: "hexpm", optional: false]}], "hexpm", "b763c0e1a9741d39a62f5a19186a342863eacbc769151c4e81db5790efecefca"},
"ekka": {:git, "https://github.com/emqx/ekka.git", "cdde7fa2db89764f5c6be69d8bc6f79f4cfa5c82", [tag: "0.10.2"]},
"ekka": {:git, "https://github.com/emqx/ekka.git", "80e7439472164ce2b121cff523b979291cc7c9f3", [tag: "0.10.8"]},
"emqtt": {:git, "https://github.com/emqx/emqtt.git", "9e867b1fcaadbfcce45ea75d3721f982907ae417", [tag: "v1.2.3"]},
"emqx_http_lib": {:git, "https://github.com/emqx/emqx_http_lib.git", "9a1aafcbad1bb35392ebabc0cf102c7bce660432", [tag: "0.4.0"]},
"epgsql": {:git, "https://github.com/epgsql/epgsql.git", "895c8f9d53f08d09ec6a0301c56d3d6f270929f2", [tag: "4.4.0"]},
@ -26,7 +26,7 @@
"jose": {:hex, :jose, "1.11.2", "f4c018ccf4fdce22c71e44d471f15f723cb3efab5d909ab2ba202b5bf35557b3", [:mix, :rebar3], [], "hexpm", "98143fbc48d55f3a18daba82d34fe48959d44538e9697c08f34200fa5f0947d2"},
"jsx": {:hex, :jsx, "3.1.0", "d12516baa0bb23a59bb35dccaf02a1bd08243fcbb9efe24f2d9d056ccff71268", [:rebar3], [], "hexpm", "0c5cc8fdc11b53cc25cf65ac6705ad39e54ecc56d1c22e4adb8f5a53fb9427f3"},
"lwm2m_coap": {:git, "https://github.com/emqx/lwm2m-coap.git", "495f3c62fae153040c89f9a0ba5344789ff5acc8", [tag: "v2.0.0"]},
"minirest": {:git, "https://github.com/emqx/minirest.git", "27ad0a8eaf10dca7748b0f63aa66754486a39dd5", [tag: "1.1.7"]},
"minirest": {:git, "https://github.com/emqx/minirest.git", "dea1f49a55d46673e2ca6400a87f8fcdee58b8ef", [tag: "1.2.2"]},
"mysql": {:git, "https://github.com/emqx/mysql-otp.git", "bdabac44cc8836a9e23897b7e1b77c7df7e04f70", [tag: "1.7.1"]},
"pbkdf2": {:git, "https://github.com/emqx/erlang-pbkdf2.git", "45d9981209ea07a83a58cf85aaf8236457da4342", [tag: "2.0.4"]},
"poolboy": {:git, "https://github.com/emqx/poolboy.git", "29be47db8c2be38b18c908e43a80ebb7b9b6116b", [tag: "1.5.2"]},

View File

@ -25,10 +25,55 @@ export RELEASE_BOOT_SCRIPT="${RELEASE_BOOT_SCRIPT:-"start"}"
export RELEASE_BOOT_SCRIPT_CLEAN="${RELEASE_BOOT_SCRIPT_CLEAN:-"start_clean"}"
export RELEASE_SYS_CONFIG="${RELEASE_SYS_CONFIG:-"$REL_VSN_DIR/sys"}"
# defined in emqx_vars
export RUNNER_ROOT_DIR
export RUNNER_ETC_DIR
export SCHEMA_MOD=emqx_machine_schema
export CONFIGS_DIR="$RUNNER_DATA_DIR/configs"
export NAME='emqx'
export NAME_TYPE='-sname'
export MNESIA_DATA_DIR="$RUNNER_DATA_DIR/mnesia"
set_name () {
IS_BOOT_COMMAND='no'
case "$1" in
start|start_iex|daemon|daemon_iex)
IS_BOOT_COMMAND='yes'
;;
esac
## Possible ways to configure emqx node name:
## 1. configure node.name in emqx.conf
## 2. override with environment variable EMQX_NODE_NAME
## Node name is either short-name (without '@'), e.g. 'emqx'
## or long name (with '@') e.g. 'emqx@example.net' or 'emqx@127.0.0.1'
NAME="${EMQX_NODE_NAME:-}"
if [ -z "$NAME" ]; then
if [ "$IS_BOOT_COMMAND" = 'yes' ]; then
# for boot commands, inspect emqx.conf for node name
NAME="$(call_hocon -s $SCHEMA_MOD -c "$RUNNER_ETC_DIR"/emqx.conf get node.name | tr -d \")"
else
# for non-boot commands, inspect vm.<time>.args for node name
# shellcheck disable=SC2012,SC2086
LATEST_VM_ARGS="$(ls -t $CONFIGS_DIR/vm.*.args | head -1)"
NAME="$(grep -E '^-s?name' "$LATEST_VM_ARGS" | awk '{print $2}')"
fi
fi
[ -z "$NAME" ] && NAME='emqx'
case "$NAME" in
*@*)
NAME_TYPE='-name'
;;
*)
NAME_TYPE='-sname'
esac
SHORT_NAME="$(echo "$NAME" | awk -F'@' '{print $1}')"
export ESCRIPT_NAME="$SHORT_NAME"
export NAME_TYPE
export NAME
}
SED_REPLACE="sed -i "
case $(sed --help 2>&1) in
@ -71,41 +116,35 @@ generate_config () {
RELEASE_SYS_CONFIG="$CONFIGS_DIR/app.$NOW_TIME.config"
RELEASE_VM_ARGS="$CONFIGS_DIR/vm.$NOW_TIME.args"
# TODO: migrate vm.args logic
# local CONF_FILE="$CONFIGS_DIR/app.$NOW_TIME.config"
# local HOCON_GEN_ARG_FILE="$CONFIGS_DIR/vm.$NOW_TIME.args"
# CONFIG_ARGS="--erl-config $CONF_FILE --vm-args $HOCON_GEN_ARG_FILE"
# ## Merge hocon generated *.args into the vm.args
# TMP_ARG_FILE="$CONFIGS_DIR/vm.args.tmp"
# cp "$RUNNER_ETC_DIR/vm.args" "$TMP_ARG_FILE"
# echo "" >> "$TMP_ARG_FILE"
# echo "-pa ${REL_DIR}/consolidated" >> "$TMP_ARG_FILE"
# ## read lines from generated vm.<time>.args file
# ## drop comment lines, and empty lines using sed
# ## pipe the lines to a while loop
# sed '/^#/d' "$HOCON_GEN_ARG_FILE" | sed '/^$/d' | while IFS='' read -r ARG_LINE || [ -n "$ARG_LINE" ]; do
# ## in the loop, split the 'key[:space:]value' pair
# ARG_KEY=$(echo "$ARG_LINE" | awk '{$NF="";print}')
# ARG_VALUE=$(echo "$ARG_LINE" | awk '{print $NF}')
# ## use the key to look up in vm.args file for the value
# TMP_ARG_VALUE=$(grep "^$ARG_KEY" "$TMP_ARG_FILE" || true | awk '{print $NF}')
# ## compare generated (to override) value to original (to be overriden) value
# if [ "$ARG_VALUE" != "$TMP_ARG_VALUE" ] ; then
# ## if they are different
# if [ -n "$TMP_ARG_VALUE" ]; then
# ## if the old value is present, replace it with generated value
# sh -c "$SED_REPLACE 's|^$ARG_KEY.*$|$ARG_LINE|' $TMP_ARG_FILE"
# else
# ## otherwise append generated value to the end
# echo "$ARG_LINE" >> "$TMP_ARG_FILE"
# fi
# fi
# done
# echo "$name_type $node_name" >> "$TMP_ARG_FILE"
# ## rename the generated vm.<time>.args file
# mv -f "$TMP_ARG_FILE" "$HOCON_GEN_ARG_FILE"
## Merge hocon generated *.args into the vm.args
TMP_ARG_FILE="$CONFIGS_DIR/vm.args.tmp"
cp "$RUNNER_ETC_DIR/vm.args" "$TMP_ARG_FILE"
echo "" >> "$TMP_ARG_FILE"
echo "-pa ${REL_VSN_DIR}/consolidated" >> "$TMP_ARG_FILE"
## read lines from generated vm.<time>.args file
## drop comment lines, and empty lines using sed
## pipe the lines to a while loop
sed '/^#/d' "$RELEASE_VM_ARGS" | sed '/^$/d' | while IFS='' read -r ARG_LINE || [ -n "$ARG_LINE" ]; do
## in the loop, split the 'key[:space:]value' pair
ARG_KEY=$(echo "$ARG_LINE" | awk '{$NF="";print}')
ARG_VALUE=$(echo "$ARG_LINE" | awk '{print $NF}')
## use the key to look up in vm.args file for the value
TMP_ARG_VALUE=$(grep "^$ARG_KEY" "$TMP_ARG_FILE" || true | awk '{print $NF}')
## compare generated (to override) value to original (to be overriden) value
if [ "$ARG_VALUE" != "$TMP_ARG_VALUE" ] ; then
## if they are different
if [ -n "$TMP_ARG_VALUE" ]; then
## if the old value is present, replace it with generated value
sh -c "$SED_REPLACE 's|^$ARG_KEY.*$|$ARG_LINE|' $TMP_ARG_FILE"
else
## otherwise append generated value to the end
echo "$ARG_LINE" >> "$TMP_ARG_FILE"
fi
fi
done
echo "$name_type $node_name" >> "$TMP_ARG_FILE"
## rename the generated vm.<time>.args file
mv -f "$TMP_ARG_FILE" "$RELEASE_VM_ARGS"
# # # shellcheck disable=SC2086
# if ! relx_nodetool chkconfig $CONFIG_ARGS; then
@ -113,7 +152,6 @@ generate_config () {
# fi
}
release_distribution () {
case $RELEASE_DISTRIBUTION in
none)
@ -148,7 +186,7 @@ start () {
exec "$REL_VSN_DIR/$REL_EXEC" \
--cookie "$RELEASE_COOKIE" \
$(release_distribution "$RELEASE_NODE") \
--erl "-mode $RELEASE_MODE" \
--erl "-mode $RELEASE_MODE -mnesia dir \"${MNESIA_DATA_DIR}\"" \
--erl-config "$RELEASE_SYS_CONFIG" \
--boot "$REL_VSN_DIR/$RELEASE_BOOT_SCRIPT" \
--boot-var RELEASE_LIB "$RELEASE_ROOT/lib" \
@ -164,6 +202,8 @@ eval_elixir () {
--vm-args "$RELEASE_VM_ARGS" --eval "$1"
}
set_name "$1"
case $1 in
start)
start "elixir" --no-halt