Parcourir la source

feat: support starting emqx from relup dir

We put all of the unpacked files into `relup` dir, and warn the user if boot from it
Shawn il y a 1 an
Parent
commit
c6b02bc13f
3 fichiers modifiés avec 45 ajouts et 35 suppressions
  1. 42 31
      bin/emqx
  2. 2 2
      rebar.config.erl
  3. 1 2
      relup/examples/5.6.1-to-5.6.1+patch.A.relup

+ 42 - 31
bin/emqx

@@ -13,6 +13,35 @@ if [ "$DEBUG" -eq 2 ]; then
   export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
   export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
 fi
 fi
 
 
+logerr() {
+    if [ "${TERM:-dumb}" = dumb ]; then
+        echo -e "ERROR: $*" 1>&2
+    else
+        echo -e "$(tput setaf 1)ERROR: $*$(tput sgr0)" 1>&2
+    fi
+}
+
+logwarn() {
+    if [ "${TERM:-dumb}" = dumb ]; then
+        echo "WARNING: $*"
+    else
+        echo "$(tput setaf 3)WARNING: $*$(tput sgr0)"
+    fi
+}
+
+logdebug() {
+    if [ "$DEBUG" -eq 1 ]; then
+        echo "DEBUG: $*"
+    fi
+}
+
+die() {
+    set +x
+    logerr "$1"
+    errno=${2:-1}
+    exit "$errno"
+}
+
 # We need to find real directory with emqx files on all platforms
 # We need to find real directory with emqx files on all platforms
 # even when bin/emqx is symlinked on several levels
 # even when bin/emqx is symlinked on several levels
 # - readlink -f works perfectly, but `-f` flag has completely different meaning in BSD version,
 # - readlink -f works perfectly, but `-f` flag has completely different meaning in BSD version,
@@ -34,6 +63,17 @@ else
     RUNNER_ROOT_DIR="$(cd "$(dirname "$(realpath "$0" || echo "$0")")"/..; pwd -P)"
     RUNNER_ROOT_DIR="$(cd "$(dirname "$(realpath "$0" || echo "$0")")"/..; pwd -P)"
 fi
 fi
 
 
+BASE_RUNNER_ROOT_DIR="${BASE_RUNNER_ROOT_DIR:-$RUNNER_ROOT_DIR}"
+
+if [ -f "$RUNNER_ROOT_DIR/relup/version" ]; then
+    TARGET_VSN=$(cat "$RUNNER_ROOT_DIR/relup/version")
+    export BASE_RUNNER_ROOT_DIR
+    logwarn "Loading emqx from hot upgrade dir: $RUNNER_ROOT_DIR/relup"
+    exec $RUNNER_ROOT_DIR/relup/$TARGET_VSN/bin/emqx "$@"
+else
+    logdebug "Loading emqx from $RUNNER_ROOT_DIR"
+fi
+
 # shellcheck disable=SC1090,SC1091
 # shellcheck disable=SC1090,SC1091
 . "$RUNNER_ROOT_DIR"/releases/emqx_vars
 . "$RUNNER_ROOT_DIR"/releases/emqx_vars
 
 
@@ -60,35 +100,6 @@ export PROGNAME="erl"
 export ERTS_LIB_DIR="$RUNNER_ROOT_DIR/lib"
 export ERTS_LIB_DIR="$RUNNER_ROOT_DIR/lib"
 DYNLIBS_DIR="$RUNNER_ROOT_DIR/dynlibs"
 DYNLIBS_DIR="$RUNNER_ROOT_DIR/dynlibs"
 
 
-logerr() {
-    if [ "${TERM:-dumb}" = dumb ]; then
-        echo -e "ERROR: $*" 1>&2
-    else
-        echo -e "$(tput setaf 1)ERROR: $*$(tput sgr0)" 1>&2
-    fi
-}
-
-logwarn() {
-    if [ "${TERM:-dumb}" = dumb ]; then
-        echo "WARNING: $*"
-    else
-        echo "$(tput setaf 3)WARNING: $*$(tput sgr0)"
-    fi
-}
-
-logdebug() {
-    if [ "$DEBUG" -eq 1 ]; then
-        echo "DEBUG: $*"
-    fi
-}
-
-die() {
-    set +x
-    logerr "$1"
-    errno=${2:-1}
-    exit "$errno"
-}
-
 assert_node_alive() {
 assert_node_alive() {
     if ! relx_nodetool "ping" > /dev/null; then
     if ! relx_nodetool "ping" > /dev/null; then
         exit 1
         exit 1
@@ -598,7 +609,7 @@ DATA_DIR="$(get_boot_config 'node.data_dir')"
 DATA_DIR="${DATA_DIR%/}"
 DATA_DIR="${DATA_DIR%/}"
 if [[ $DATA_DIR != /* ]]; then
 if [[ $DATA_DIR != /* ]]; then
     # relative path
     # relative path
-    DATA_DIR="${RUNNER_ROOT_DIR}/${DATA_DIR}"
+    DATA_DIR="${BASE_RUNNER_ROOT_DIR}/${DATA_DIR}"
 fi
 fi
 CONFIGS_DIR="$DATA_DIR/configs"
 CONFIGS_DIR="$DATA_DIR/configs"
 mkdir -p "$CONFIGS_DIR"
 mkdir -p "$CONFIGS_DIR"
@@ -1060,7 +1071,7 @@ nodetool_shutdown() {
     logger -t "${REL_NAME}[${PID}]" "STOP: OK"
     logger -t "${REL_NAME}[${PID}]" "STOP: OK"
 }
 }
 
 
-cd "$RUNNER_ROOT_DIR"
+cd "$BASE_RUNNER_ROOT_DIR"
 
 
 case "${COMMAND}" in
 case "${COMMAND}" in
     start)
     start)

+ 2 - 2
rebar.config.erl

@@ -392,9 +392,9 @@ overlay_vars_pkg(bin) ->
         {platform_etc_dir, "etc"},
         {platform_etc_dir, "etc"},
         {platform_plugins_dir, "plugins"},
         {platform_plugins_dir, "plugins"},
         {runner_bin_dir, "$RUNNER_ROOT_DIR/bin"},
         {runner_bin_dir, "$RUNNER_ROOT_DIR/bin"},
-        {emqx_etc_dir, "$RUNNER_ROOT_DIR/etc"},
+        {emqx_etc_dir, "$BASE_RUNNER_ROOT_DIR/etc"},
         {runner_lib_dir, "$RUNNER_ROOT_DIR/lib"},
         {runner_lib_dir, "$RUNNER_ROOT_DIR/lib"},
-        {runner_log_dir, "$RUNNER_ROOT_DIR/log"},
+        {runner_log_dir, "$BASE_RUNNER_ROOT_DIR/log"},
         {runner_user, ""},
         {runner_user, ""},
         {is_elixir, "no"}
         {is_elixir, "no"}
     ];
     ];

+ 1 - 2
relup/examples/5.6.1-to-5.6.1+patch.A.relup

@@ -14,8 +14,7 @@
     target_version => "5.6.1+patch.A",
     target_version => "5.6.1+patch.A",
     from_version => "5.6.1",
     from_version => "5.6.1",
     code_changes =>
     code_changes =>
-        [ {load_module, emqx_post_upgrade}
-        , {load_module, emqx_broker}
+        [ {load_module, emqx_broker}
         , {load_module, emqx_metrics}
         , {load_module, emqx_metrics}
         , {load_module, emqx_persistent_message}
         , {load_module, emqx_persistent_message}
         , {load_module, emqx_dashboard_monitor}
         , {load_module, emqx_dashboard_monitor}