refactor(bin/emqx): wait for up to 120 seconds by default

This commit is contained in:
Zaiming (Stone) Shi 2021-12-31 15:05:40 +01:00
parent 8ba059bcd7
commit 320506957c
3 changed files with 90 additions and 9 deletions

View File

@ -578,15 +578,14 @@ case "${COMMAND}" in
"$BINDIR/run_erl" -daemon "$PIPE_DIR" "$RUNNER_LOG_DIR" \ "$BINDIR/run_erl" -daemon "$PIPE_DIR" "$RUNNER_LOG_DIR" \
"$(relx_start_command)" "$(relx_start_command)"
WAIT_TIME=${WAIT_FOR_ERLANG:-15} WAIT_TIME=${EMQX_WAIT_FOR_START:-120}
if wait_for "$WAIT_TIME" 'relx_nodetool' 'ping'; then if wait_for "$WAIT_TIME" 'relx_nodetool' 'ping'; then
echo "$EMQX_DESCRIPTION $REL_VSN is started successfully!" echo "$EMQX_DESCRIPTION $REL_VSN is started successfully!"
exit 0 exit 0
else else
echo "$EMQX_DESCRIPTION $REL_VSN failed to start within ${WAIT_TIME} seconds," echo "$EMQX_DESCRIPTION $REL_VSN failed to start in ${WAIT_TIME} seconds."
echo "see the output of '$0 console' for more information." echo "Please find more information in erlang.log.N"
echo "If you want to wait longer, set the environment variable" echo "Or run 'DEBUG=1 $0 console' to have logs printed to console."
echo "WAIT_FOR_ERLANG to the number of seconds to wait."
exit 1 exit 1
fi fi
;; ;;
@ -598,13 +597,13 @@ case "${COMMAND}" in
echoerr "Graceful shutdown failed PID=[$PID]" echoerr "Graceful shutdown failed PID=[$PID]"
exit 1 exit 1
fi fi
WAIT_TIME="${WAIT_FOR_ERLANG_STOP:-60}" WAIT_TIME="${EMQX_WAIT_FOR_STOP:-120}"
if ! wait_for "$WAIT_TIME" 'is_down' "$PID"; then if ! wait_for "$WAIT_TIME" 'is_down' "$PID"; then
msg="dangling after ${WAIT_TIME} seconds" msg="dangling after ${WAIT_TIME} seconds"
# also log to syslog # also log to syslog
logger -t "${REL_NAME}[${PID}]" "STOP: $msg" logger -t "${REL_NAME}[${PID}]" "STOP: $msg"
# log to user console # log to user console
echoerr "stop failed, $msg" echoerr "Stop failed, $msg"
echo "ERROR: $PID is still around" echo "ERROR: $PID is still around"
ps -p "$PID" ps -p "$PID"
exit 1 exit 1

84
scripts/buildx.sh Executable file
View File

@ -0,0 +1,84 @@
#!/usr/bin/env bash
## This script helps to run docker buildx to build cross-arch/platform packages (linux only)
## It mounts (not copy) host directory to a cross-arch/platform builder container
## Make sure the source dir (specified by --src_dir option) is clean before running this script
## NOTE: it requires $USER in docker group
## i.e. will not work if docker command has to be executed with sudo
## example:
## ./scripts/buildx.sh --profile emqx --pkgtype zip --arch arm64 --builder ghcr.io/emqx/emqx-builder/4.4-4:24.1.5-3-debian10
set -euo pipefail
help() {
echo
echo "-h|--help: To display this usage information"
echo "--profile <PROFILE>: EMQ X profile to build, e.g. emqx, emqx-edge"
echo "--pkgtype zip|pkg: Specify which package to build, zip for .zip and pkg for .rpm or .deb"
echo "--arch amd64|arm64: Target arch to build the EMQ X package for"
echo "--src_dir <SRC_DIR>: EMQ X source ode in this dir, default to PWD"
echo "--builder <BUILDER>: Builder image to pull"
echo " E.g. ghcr.io/emqx/emqx-builder/4.4-4:24.1.5-3-debian10"
}
while [ "$#" -gt 0 ]; do
case $1 in
-h|--help)
help
exit 0
;;
--src_dir)
SRC_DIR="$2"
shift 2
;;
--profile)
PROFILE="$2"
shift 2
;;
--pkgtype)
PKGTYPE="$2"
shift 2
;;
--builder)
BUILDER="$2"
shift 2
;;
--arch)
ARCH="$2"
shift 2
;;
*)
echo "WARN: Unknown arg (ignored): $1"
shift
continue
;;
esac
done
if [ -z "${PROFILE:-}" ] || [ -z "${PKGTYPE:-}" ] || [ -z "${BUILDER:-}" ] || [ -z "${ARCH:-}" ]; then
help
exit 1
fi
if [ "$PKGTYPE" != 'zip' ] && [ "$PKGTYPE" != 'pkg' ]; then
echo "Bad --pkgtype option, should be zip or pkg"
exit 1
fi
cd "${SRC_DIR:-.}"
PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh)}"
OTP_VSN_SYSTEM=$(echo "$BUILDER" | cut -d ':' -f2)
PKG_NAME="${PROFILE}-${PKG_VSN}-otp${OTP_VSN_SYSTEM}-${ARCH}"
docker info
docker run --rm --privileged tonistiigi/binfmt:latest --install "${ARCH}"
docker run -i --rm \
-v "$(pwd)":/emqx \
--workdir /emqx \
--platform="linux/$ARCH" \
-e EMQX_NAME="$PROFILE" \
"$BUILDER" \
bash -euc "make ${PROFILE}-${PKGTYPE} && .ci/build_packages/tests.sh $PKG_NAME $PKGTYPE"

View File

@ -37,7 +37,6 @@ docker run -d -t --restart=always --name "$NODE1" \
--net "$NET" \ --net "$NET" \
-e EMQX_NODE_NAME="emqx@$NODE1" \ -e EMQX_NODE_NAME="emqx@$NODE1" \
-e EMQX_NODE_COOKIE="$COOKIE" \ -e EMQX_NODE_COOKIE="$COOKIE" \
-e WAIT_FOR_ERLANG=60 \
-p 18083:18083 \ -p 18083:18083 \
-v "$PROJ_DIR"/_build/emqx/rel/emqx:/built \ -v "$PROJ_DIR"/_build/emqx/rel/emqx:/built \
"$IMAGE" sh -c 'cp -r /built /emqx && /emqx/bin/emqx console' "$IMAGE" sh -c 'cp -r /built /emqx && /emqx/bin/emqx console'
@ -46,7 +45,6 @@ docker run -d -t --restart=always --name "$NODE2" \
--net "$NET" \ --net "$NET" \
-e EMQX_NODE_NAME="emqx@$NODE2" \ -e EMQX_NODE_NAME="emqx@$NODE2" \
-e EMQX_NODE_COOKIE="$COOKIE" \ -e EMQX_NODE_COOKIE="$COOKIE" \
-e WAIT_FOR_ERLANG=60 \
-p 18084:18083 \ -p 18084:18083 \
-v "$PROJ_DIR"/_build/emqx/rel/emqx:/built \ -v "$PROJ_DIR"/_build/emqx/rel/emqx:/built \
"$IMAGE" sh -c 'cp -r /built /emqx && /emqx/bin/emqx console' "$IMAGE" sh -c 'cp -r /built /emqx && /emqx/bin/emqx console'