Merge pull request #11716 from sstrigler/dev_script_sname

some minor improvements to ./dev
This commit is contained in:
Stefan Strigler 2023-10-04 08:57:56 +02:00 committed by GitHub
commit e049dc0e76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 6 deletions

38
dev
View File

@ -40,11 +40,13 @@ COMMANDS:
eval: Evaluate an Erlang expression eval: Evaluate an Erlang expression
OPTIONS: OPTIONS:
-h|--help: Print this usage info.
-p|--profile: emqx | emqx-enterprise, defaults to 'PROFILE' env. -p|--profile: emqx | emqx-enterprise, defaults to 'PROFILE' env.
-c|--compile: Force recompile, otherwise starts with the already built libs -c|--compile: Force recompile, otherwise starts with the already built libs
in '_build/\$PROFILE/lib/'. in '_build/\$PROFILE/lib/'.
-e|--ekka-epmd: Force to use ekka_epmd. -e|--ekka-epmd: Force to use ekka_epmd.
-n|--name: Node name, defaults to \$EMQX_NODE__NAME or the \$EMQX_NODE_NAME env. -n|--name: Node name, defaults to \$EMQX_NODE__NAME or the \$EMQX_NODE_NAME env.
-s|--shortnames: Use shortnames for erlang node name (ie. use -sname parameter).
ENVIRONMENT VARIABLES: ENVIRONMENT VARIABLES:
@ -69,6 +71,7 @@ PROFILE="${PROFILE:-emqx}"
FORCE_COMPILE=0 FORCE_COMPILE=0
# Do not start using ekka epmd by default, so your IDE can connect to it # Do not start using ekka epmd by default, so your IDE can connect to it
EKKA_EPMD=0 EKKA_EPMD=0
SHORTNAMES=0
COMMAND='run' COMMAND='run'
case "${1:-novalue}" in case "${1:-novalue}" in
novalue) novalue)
@ -98,6 +101,10 @@ esac
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
case $1 in case $1 in
-h|--help)
usage
exit 0
;;
-n|--name) -n|--name)
EMQX_NODE_NAME="$2" EMQX_NODE_NAME="$2"
shift 1 shift 1
@ -112,6 +119,9 @@ while [ "$#" -gt 0 ]; do
-e|--ekka-epmd) -e|--ekka-epmd)
EKKA_EPMD=1 EKKA_EPMD=1
;; ;;
-s|--shortnames)
SHORTNAMES=1
;;
--) --)
shift shift
PASSTHROUGH_ARGS=("$@") PASSTHROUGH_ARGS=("$@")
@ -119,6 +129,7 @@ while [ "$#" -gt 0 ]; do
;; ;;
*) *)
logerr "Unknown argument $1" logerr "Unknown argument $1"
usage
exit 1 exit 1
;; ;;
esac esac
@ -171,6 +182,12 @@ else
EPMD_ARGS='' EPMD_ARGS=''
fi fi
if [ $SHORTNAMES -eq 1 ]; then
ERL_NAME_ARG='-sname'
else
ERL_NAME_ARG='-name'
fi
## build compile the profile is it's not compiled yet ## build compile the profile is it's not compiled yet
prepare_erl_libs() { prepare_erl_libs() {
@ -206,6 +223,13 @@ prepare_erl_libs() {
fi fi
done done
fi fi
if [ -e "_build/${profile}/checkouts" ]; then
for app in "_build/${profile}/checkouts"/*; do
erl_libs="${erl_libs}${sep}${app}"
done
else
echo "no checkouts"
fi
export ERL_LIBS="$erl_libs" export ERL_LIBS="$erl_libs"
} }
@ -288,7 +312,7 @@ append_args_file() {
## ensure a new line at the end ## ensure a new line at the end
echo '' >> "$ARGS_FILE" echo '' >> "$ARGS_FILE"
cat <<EOF >> "$ARGS_FILE" cat <<EOF >> "$ARGS_FILE"
-name $EMQX_NODE_NAME $ERL_NAME_ARG $EMQX_NODE_NAME
-mnesia dir '"$EMQX_DATA_DIR/mnesia/$EMQX_NODE_NAME"' -mnesia dir '"$EMQX_DATA_DIR/mnesia/$EMQX_NODE_NAME"'
-stdlib restricted_shell emqx_restricted_shell -stdlib restricted_shell emqx_restricted_shell
+spp true +spp true
@ -386,7 +410,7 @@ boot() {
# shellcheck disable=SC2086 # shellcheck disable=SC2086
env APPS="$APPS" iex \ env APPS="$APPS" iex \
--name "$EMQX_NODE_NAME" \ -$ERL_NAME_ARG "$EMQX_NODE_NAME" \
--erl "$EPMD_ARGS_ELIXIR" \ --erl "$EPMD_ARGS_ELIXIR" \
--erl '-user Elixir.IEx.CLI' \ --erl '-user Elixir.IEx.CLI' \
--erl '-proto_dist ekka' \ --erl '-proto_dist ekka' \
@ -402,7 +426,7 @@ boot() {
" "
# shellcheck disable=SC2086 # shellcheck disable=SC2086
erl -name "$EMQX_NODE_NAME" \ erl $ERL_NAME_ARG "$EMQX_NODE_NAME" \
$EPMD_ARGS \ $EPMD_ARGS \
-proto_dist ekka \ -proto_dist ekka \
-args_file "$ARGS_FILE" \ -args_file "$ARGS_FILE" \
@ -416,14 +440,18 @@ boot() {
gen_tmp_node_name() { gen_tmp_node_name() {
local rnd local rnd
rnd="$(od -t u -N 4 /dev/urandom | head -n1 | awk '{print $2 % 1000}')" rnd="$(od -t u -N 4 /dev/urandom | head -n1 | awk '{print $2 % 1000}')"
if [ $SHORTNAMES -eq 1 ]; then
echo "remsh${rnd}"
else
echo "remsh${rnd}-${EMQX_NODE_NAME}" echo "remsh${rnd}-${EMQX_NODE_NAME}"
fi
} }
remsh() { remsh() {
local tmpnode local tmpnode
tmpnode="$(gen_tmp_node_name)" tmpnode="$(gen_tmp_node_name)"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
erl -name "$tmpnode" \ erl $ERL_NAME_ARG "$tmpnode" \
-hidden \ -hidden \
-setcookie "$COOKIE" \ -setcookie "$COOKIE" \
-remsh "$EMQX_NODE_NAME" \ -remsh "$EMQX_NODE_NAME" \
@ -436,7 +464,7 @@ eval_remsh_erl() {
tmpnode="$(gen_tmp_node_name)" tmpnode="$(gen_tmp_node_name)"
erl_code="$1" erl_code="$1"
# shellcheck disable=SC2086 # need to expand EMQD_ARGS # shellcheck disable=SC2086 # need to expand EMQD_ARGS
erl -name "$tmpnode" -setcookie "$COOKIE" -hidden -noshell $EPMD_ARGS -eval "$erl_code" 2>&1 erl $ERL_NAME_ARG "$tmpnode" -setcookie "$COOKIE" -hidden -noshell $EPMD_ARGS -eval "$erl_code" 2>&1
} }
ctl() { ctl() {