mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-12-04 21:27:39 +08:00
82 lines
2.4 KiB
Bash
82 lines
2.4 KiB
Bash
#!/bin/sh
|
|
# -*- tab-width:4;indent-tabs-mode:nil -*-
|
|
# ex: ts=4 sw=4 et
|
|
|
|
set -e
|
|
|
|
REL_NAME="emqx"
|
|
|
|
## constants from relx template
|
|
RUNNER_ROOT_DIR="$(cd $(dirname $(readlink $0 || echo $0))/..; pwd -P)"
|
|
ERTS_VSN="10.3"
|
|
RUNNER_ETC_DIR="$RUNNER_ROOT_DIR/etc"
|
|
|
|
if [ -z "$WITH_EPMD" ]; then
|
|
EPMD_ARG="-start_epmd false -epmd_module nodetool_epmd"
|
|
else
|
|
EPMD_ARG="-start_epmd true"
|
|
fi
|
|
|
|
relx_get_nodename() {
|
|
id="longname$(relx_gen_id)-${NAME}"
|
|
"$BINDIR/erl" -boot start_clean -eval '[Host] = tl(string:tokens(atom_to_list(node()),"@")), io:format("~s~n", [Host]), halt()' -noshell ${NAME_TYPE} $id
|
|
}
|
|
|
|
# Control a node
|
|
relx_nodetool() {
|
|
command="$1"; shift
|
|
|
|
ERL_FLAGS="$ERL_FLAGS $EPMD_ARG $PROTO_DIST_ARG" \
|
|
"$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \
|
|
-setcookie "$COOKIE" "$command" "$@"
|
|
}
|
|
|
|
|
|
[ "x" = "x$EMQX_NODE_NAME" ] || NAME_ARG="-name $EMQX_NODE_NAME"
|
|
# Extract the target node name from node.args
|
|
if [ -z "$NAME_ARG" ]; then
|
|
NODENAME=`egrep '^[ \t]*node.name[ \t]*=[ \t]*' $RUNNER_ETC_DIR/emqx.conf 2> /dev/null | tail -1 | cut -d = -f 2-`
|
|
if [ -z "$NODENAME" ]; then
|
|
echoerr "vm.args needs to have a -name parameter."
|
|
echoerr " -sname is not supported."
|
|
exit 1
|
|
else
|
|
NAME_ARG="-name ${NODENAME# *}"
|
|
fi
|
|
fi
|
|
|
|
# Extract the name type and name from the NAME_ARG for REMSH
|
|
NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')"
|
|
NAME="$(echo "$NAME_ARG" | awk '{print $2}')"
|
|
|
|
[ "x" = "x$EMQX_NODE_COOKIE" ] || COOKIE_ARG="-setcookie $EMQX_NODE_COOKIE"
|
|
# Extract the target cookie
|
|
if [ -z "$COOKIE_ARG" ]; then
|
|
COOKIE=`egrep '^[ \t]*node.cookie[ \t]*=[ \t]*' $RUNNER_ETC_DIR/emqx.conf 2> /dev/null | tail -1 | cut -d = -f 2-`
|
|
if [ -z "$COOKIE" ]; then
|
|
echoerr "vm.args needs to have a -setcookie parameter."
|
|
exit 1
|
|
else
|
|
COOKIE_ARG="-setcookie $COOKIE"
|
|
fi
|
|
fi
|
|
|
|
# Extract cookie name from COOKIE_ARG
|
|
COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')"
|
|
|
|
# Support for IPv6 Dist. See: https://hub.fastgit.org/emqtt/emqttd/issues/1460
|
|
PROTO_DIST=`egrep '^[ \t]*cluster.proto_dist[ \t]*=[ \t]*' $RUNNER_ETC_DIR/emqx.conf 2> /dev/null | tail -1 | cut -d = -f 2-`
|
|
if [ -z "$PROTO_DIST" ]; then
|
|
PROTO_DIST_ARG=""
|
|
else
|
|
PROTO_DIST_ARG="-proto_dist $PROTO_DIST"
|
|
fi
|
|
|
|
export ROOTDIR="$RUNNER_ROOT_DIR"
|
|
export ERTS_DIR="$ROOTDIR/erts-$ERTS_VSN"
|
|
export BINDIR="$ERTS_DIR/bin"
|
|
cd "$ROOTDIR"
|
|
|
|
relx_nodetool rpc emqx_ctl run_command "$@"
|
|
|