chore: refine boot script with more readable help info
This commit is contained in:
parent
5e652217c8
commit
2da27392f7
246
bin/emqx
246
bin/emqx
|
@ -31,6 +31,12 @@ ERTS_LIB_DIR="$ERTS_DIR/../lib"
|
||||||
# Echo to stderr on errors
|
# Echo to stderr on errors
|
||||||
echoerr() { echo "$*" 1>&2; }
|
echoerr() { echo "$*" 1>&2; }
|
||||||
|
|
||||||
|
assert_node_alive() {
|
||||||
|
if ! relx_nodetool "ping" > /dev/null; then
|
||||||
|
die "node_is_not_running!" 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
check_eralng_start() {
|
check_eralng_start() {
|
||||||
"$BINDIR/$PROGNAME" -noshell -boot "$REL_DIR/start_clean" -s crypto start -s init stop
|
"$BINDIR/$PROGNAME" -noshell -boot "$REL_DIR/start_clean" -s crypto start -s init stop
|
||||||
}
|
}
|
||||||
|
@ -60,62 +66,157 @@ fi
|
||||||
# cuttlefish try to read environment variables starting with "EMQX_"
|
# cuttlefish try to read environment variables starting with "EMQX_"
|
||||||
export CUTTLEFISH_ENV_OVERRIDE_PREFIX='EMQX_'
|
export CUTTLEFISH_ENV_OVERRIDE_PREFIX='EMQX_'
|
||||||
|
|
||||||
relx_usage() {
|
usage() {
|
||||||
command="$1"
|
local command="$1"
|
||||||
|
|
||||||
case "$command" in
|
case "$command" in
|
||||||
unpack)
|
start)
|
||||||
echo "Usage: $REL_NAME unpack [VERSION]"
|
echo "Start EMQX service in daemon mode"
|
||||||
echo "Unpacks a release package VERSION, it assumes that this"
|
;;
|
||||||
echo "release package tarball has already been deployed at one"
|
stop)
|
||||||
echo "of the following locations:"
|
echo "Stop the running EMQX program"
|
||||||
echo " releases/<relname>-<version>.tar.gz"
|
;;
|
||||||
echo " releases/<relname>-<version>.zip"
|
console)
|
||||||
;;
|
echo "Boot up EMQX service in an interactive Erlang shell"
|
||||||
install)
|
echo "This command needs a tty"
|
||||||
echo "Usage: $REL_NAME install [VERSION]"
|
;;
|
||||||
echo "Installs a release package VERSION, it assumes that this"
|
console_clean)
|
||||||
echo "release package tarball has already been deployed at one"
|
echo "This command does NOT boot up the EMQX service"
|
||||||
echo "of the following locations:"
|
echo "It only starts an interactive Erlang shell with all the"
|
||||||
echo " releases/<relname>-<version>.tar.gz"
|
echo "EMQX code available"
|
||||||
echo " releases/<relname>-<version>.zip"
|
;;
|
||||||
echo ""
|
foreground)
|
||||||
echo " --no-permanent Install release package VERSION but"
|
echo "Start EMQX in foreground mode without an interactive shell"
|
||||||
echo " don't make it permanent"
|
;;
|
||||||
;;
|
pid)
|
||||||
uninstall)
|
echo "Print out EMQX process identifier"
|
||||||
echo "Usage: $REL_NAME uninstall [VERSION]"
|
;;
|
||||||
echo "Uninstalls a release VERSION, it will only accept"
|
ping)
|
||||||
echo "versions that are not currently in use"
|
echo "Check if the EMQX node is up and running"
|
||||||
;;
|
echo "This command exit with 0 silently if node is running"
|
||||||
upgrade)
|
;;
|
||||||
echo "Usage: $REL_NAME upgrade [VERSION]"
|
escript)
|
||||||
echo "Upgrades the currently running release to VERSION, it assumes"
|
echo "Execute a escript using the Erlang runtime from EMQX package installation"
|
||||||
echo "that a release package tarball has already been deployed at one"
|
echo "For example $REL_NAME escript /path/to/my/escript my_arg1 my_arg2"
|
||||||
echo "of the following locations:"
|
;;
|
||||||
echo " releases/<relname>-<version>.tar.gz"
|
attach)
|
||||||
echo " releases/<relname>-<version>.zip"
|
echo "This command is applicable when EMQX is started in daemon mode."
|
||||||
echo ""
|
echo "It attaches the current shell to EMQX's control console"
|
||||||
echo " --no-permanent Install release package VERSION but"
|
echo "through a named pipe."
|
||||||
echo " don't make it permanent"
|
echo "WARNING: try to use the safer alternative, remote_console command."
|
||||||
;;
|
;;
|
||||||
downgrade)
|
remote_console)
|
||||||
echo "Usage: $REL_NAME downgrade [VERSION]"
|
echo "Start an interactive shell running an Erlang node which "
|
||||||
echo "Downgrades the currently running release to VERSION, it assumes"
|
echo "hidden-connects to the running EMQX node".
|
||||||
echo "that a release package tarball has already been deployed at one"
|
echo "This command is mostly used for troubleshooting."
|
||||||
echo "of the following locations:"
|
;;
|
||||||
echo " releases/<relname>-<version>.tar.gz"
|
ertspath)
|
||||||
echo " releases/<relname>-<version>.zip"
|
echo "Print path to Erlang runtime dir"
|
||||||
echo ""
|
;;
|
||||||
echo " --no-permanent Install release package VERSION but"
|
rpc)
|
||||||
echo " don't make it permanent"
|
echo "Usge $REL_NAME rpc MODULE FUNCTION [ARGS, ...]"
|
||||||
;;
|
echo "Connect to the EMQX node and make an Erlang RPC"
|
||||||
*)
|
echo "This command blocks for at most 60 seconds."
|
||||||
echo "Usage: $REL_NAME {start|start_boot <file>|ertspath|foreground|stop|restart|reboot|pid|ping|console|console_clean|console_boot <file>|attach|remote_console|upgrade|downgrade|install|uninstall|versions|escript|rpc|rpcterms|eval|root_dir}"
|
echo "It exits with non-zero code in case of any RPC failure"
|
||||||
;;
|
echo "including connection error and runtime exception"
|
||||||
|
;;
|
||||||
|
rpcterms)
|
||||||
|
echo "Usge $REL_NAME rpcterms MODULE FUNCTION [ARGS, ...]"
|
||||||
|
echo "Connect to the EMQX node and make an Erlang RPC"
|
||||||
|
echo "The result of the RPC call is pretty-printed as an "
|
||||||
|
echo "Erlang term"
|
||||||
|
;;
|
||||||
|
root_dir)
|
||||||
|
echo "Print EMQX installation root dir"
|
||||||
|
;;
|
||||||
|
eval)
|
||||||
|
echo "Evaluate an Erlang expression in the EMQX node"
|
||||||
|
;;
|
||||||
|
versions)
|
||||||
|
echo "List installed EMQX versions and their status"
|
||||||
|
;;
|
||||||
|
unpack)
|
||||||
|
echo "Usage: $REL_NAME unpack [VERSION]"
|
||||||
|
echo "Unpacks a release package VERSION, it assumes that this"
|
||||||
|
echo "release package tarball has already been deployed at one"
|
||||||
|
echo "of the following locations:"
|
||||||
|
echo " releases/<relname>-<version>.zip"
|
||||||
|
;;
|
||||||
|
install)
|
||||||
|
echo "Usage: $REL_NAME install [VERSION]"
|
||||||
|
echo "Installs a release package VERSION, it assumes that this"
|
||||||
|
echo "release package tarball has already been deployed at one"
|
||||||
|
echo "of the following locations:"
|
||||||
|
echo " releases/<relname>-<version>.zip"
|
||||||
|
echo ""
|
||||||
|
echo " --no-permanent Install release package VERSION but"
|
||||||
|
echo " don't make it permanent"
|
||||||
|
;;
|
||||||
|
uninstall)
|
||||||
|
echo "Usage: $REL_NAME uninstall [VERSION]"
|
||||||
|
echo "Uninstalls a release VERSION, it will only accept"
|
||||||
|
echo "versions that are not currently in use"
|
||||||
|
;;
|
||||||
|
upgrade)
|
||||||
|
echo "Usage: $REL_NAME upgrade [VERSION]"
|
||||||
|
echo "Upgrades the currently running release to VERSION, it assumes"
|
||||||
|
echo "that a release package tarball has already been deployed at one"
|
||||||
|
echo "of the following locations:"
|
||||||
|
echo " releases/<relname>-<version>.zip"
|
||||||
|
echo ""
|
||||||
|
echo " --no-permanent Install release package VERSION but"
|
||||||
|
echo " don't make it permanent"
|
||||||
|
;;
|
||||||
|
downgrade)
|
||||||
|
echo "Usage: $REL_NAME downgrade [VERSION]"
|
||||||
|
echo "Downgrades the currently running release to VERSION, it assumes"
|
||||||
|
echo "that a release package tarball has already been deployed at one"
|
||||||
|
echo "of the following locations:"
|
||||||
|
echo " releases/<relname>-<version>.zip"
|
||||||
|
echo ""
|
||||||
|
echo " --no-permanent Install release package VERSION but"
|
||||||
|
echo " don't make it permanent"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $REL_NAME COMMAND [help]"
|
||||||
|
echo ''
|
||||||
|
echo "Commonly used COMMANDs:"
|
||||||
|
echo " start: Start EMQX in daemon mode"
|
||||||
|
echo " console: Start EMQX in an interactive Erlang shell"
|
||||||
|
echo " foreground: Start EMQX in foreground mode without an interactive shell"
|
||||||
|
echo " stop: Stop the running EMQX node"
|
||||||
|
echo " ctl: Administration commands, execute '$REL_NAME ctl help' for more details"
|
||||||
|
echo ''
|
||||||
|
echo "More:"
|
||||||
|
echo " Shell attach: remote_console | attach"
|
||||||
|
echo " Up/Down-grade: upgrade | downgrade | install | uninstall"
|
||||||
|
echo " Install info: ertspath | root_dir | versions"
|
||||||
|
echo " Runtime info: pid | ping | versions"
|
||||||
|
echo " Advanced: console_clean | escript | rpc | rpcterms | eval"
|
||||||
|
echo ''
|
||||||
|
echo "Execute '$REL_NAME COMMAND help' for more information"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
COMMAND="${1:-}"
|
||||||
|
|
||||||
|
if [ -z "$COMMAND" ]; then
|
||||||
|
usage 'help'
|
||||||
|
exit 1
|
||||||
|
elif [ "$COMMAND" = 'help' ]; then
|
||||||
|
usage 'help'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${2:-}" = 'help' ]; then
|
||||||
|
## 'ctl' command has its own usage info
|
||||||
|
if [ "$COMMAND" != 'ctl' ]; then
|
||||||
|
usage "$COMMAND"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Simple way to check the correct user and fail early
|
# Simple way to check the correct user and fail early
|
||||||
check_user() {
|
check_user() {
|
||||||
# Validate that the user running the script is the owner of the
|
# Validate that the user running the script is the owner of the
|
||||||
|
@ -135,7 +236,6 @@ check_user() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Make sure the user running this script is the owner and/or su to that user
|
# Make sure the user running this script is the owner and/or su to that user
|
||||||
check_user "$@"
|
check_user "$@"
|
||||||
ES=$?
|
ES=$?
|
||||||
|
@ -357,9 +457,10 @@ if [ -z "$NAME_ARG" ]; then
|
||||||
if [ "$IS_BOOT_COMMAND" = 'no' ]; then
|
if [ "$IS_BOOT_COMMAND" = 'no' ]; then
|
||||||
# for non-boot commands, inspect vm.<time>.args for node name
|
# for non-boot commands, inspect vm.<time>.args for node name
|
||||||
# shellcheck disable=SC2012,SC2086
|
# shellcheck disable=SC2012,SC2086
|
||||||
LATEST_VM_ARGS="$(ls -t $RUNNER_DATA_DIR/configs/vm.*.args | head -1)"
|
LATEST_VM_ARGS="$(ls -t $RUNNER_DATA_DIR/configs/vm.*.args 2>/dev/null | head -1)"
|
||||||
if [ -z "$LATEST_VM_ARGS" ]; then
|
if [ -z "$LATEST_VM_ARGS" ]; then
|
||||||
echo "For command $1, there is no vm.*.args config file found in $RUNNER_DATA_DIR/configs/"
|
echoerr "For command $1, there is no vm.*.args config file found in $RUNNER_DATA_DIR/configs/"
|
||||||
|
echoerr "Please make sure the node is initialized (started for at least once)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
NODENAME="$(grep -E '^-name' "$LATEST_VM_ARGS" | awk '{print $2}')"
|
NODENAME="$(grep -E '^-name' "$LATEST_VM_ARGS" | awk '{print $2}')"
|
||||||
|
@ -709,50 +810,35 @@ case "$1" in
|
||||||
ertspath)
|
ertspath)
|
||||||
echo "$ERTS_PATH"
|
echo "$ERTS_PATH"
|
||||||
;;
|
;;
|
||||||
rpc)
|
|
||||||
# Make sure a node IS running
|
|
||||||
if ! relx_nodetool "ping" > /dev/null; then
|
|
||||||
echo "Node is not running!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
ctl)
|
||||||
|
assert_node_alive
|
||||||
shift
|
shift
|
||||||
|
relx_nodetool rpc_infinity emqx_ctl run_command "$@"
|
||||||
|
;;
|
||||||
|
|
||||||
|
rpc)
|
||||||
|
assert_node_alive
|
||||||
|
shift
|
||||||
relx_nodetool rpc "$@"
|
relx_nodetool rpc "$@"
|
||||||
;;
|
;;
|
||||||
rpcterms)
|
rpcterms)
|
||||||
# Make sure a node IS running
|
assert_node_alive
|
||||||
if ! relx_nodetool "ping" > /dev/null; then
|
|
||||||
echo "Node is not running!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
shift
|
shift
|
||||||
|
|
||||||
relx_nodetool rpcterms "$@"
|
relx_nodetool rpcterms "$@"
|
||||||
;;
|
;;
|
||||||
root_dir)
|
root_dir)
|
||||||
# Make sure a node IS running
|
assert_node_alive
|
||||||
if ! relx_nodetool "ping" > /dev/null; then
|
|
||||||
echo "Node is not running!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
shift
|
shift
|
||||||
relx_nodetool "eval" 'code:root_dir()'
|
relx_nodetool "eval" 'code:root_dir()'
|
||||||
;;
|
;;
|
||||||
eval)
|
eval)
|
||||||
# Make sure a node IS running
|
assert_node_alive
|
||||||
if ! relx_nodetool "ping" > /dev/null; then
|
|
||||||
echo "Node is not running!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
shift
|
shift
|
||||||
relx_nodetool "eval" "$@"
|
relx_nodetool "eval" "$@"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
relx_usage "$1"
|
usage "$COMMAND"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in New Issue