Sfoglia il codice sorgente

refactor: grep with --color=never

Zaiming (Stone) Shi 3 anni fa
parent
commit
cc9ee34eff
3 ha cambiato i file con 15 aggiunte e 14 eliminazioni
  1. 13 12
      bin/emqx
  2. 1 1
      changes/v5.0.18/fix-9961.en.md
  3. 1 1
      changes/v5.0.18/fix-9961.zh.md

+ 13 - 12
bin/emqx

@@ -230,6 +230,7 @@ usage() {
 }
 }
 
 
 COMMAND="${1:-}"
 COMMAND="${1:-}"
+GREP='grep --color=never'
 
 
 if [ -z "$COMMAND" ]; then
 if [ -z "$COMMAND" ]; then
     usage 'help'
     usage 'help'
@@ -340,7 +341,7 @@ if [ "$IS_BOOT_COMMAND" = 'yes' ]; then
     # Read BUILD_INFO early as the next commands may mess up the shell
     # Read BUILD_INFO early as the next commands may mess up the shell
     BUILD_INFO="$(cat "${REL_DIR}/BUILD_INFO")"
     BUILD_INFO="$(cat "${REL_DIR}/BUILD_INFO")"
     COMPATIBILITY_INFO="$(compatiblity_info 2>/dev/null || true)"
     COMPATIBILITY_INFO="$(compatiblity_info 2>/dev/null || true)"
-    if ! (echo -e "$COMPATIBILITY_INFO" | grep -q 'CRYPTO_OK'); then
+    if ! (echo -e "$COMPATIBILITY_INFO" | $GREP -q 'CRYPTO_OK'); then
         ## failed to start, might be due to missing libs, try to be portable
         ## failed to start, might be due to missing libs, try to be portable
         export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-$DYNLIBS_DIR}"
         export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-$DYNLIBS_DIR}"
         if [ "$LD_LIBRARY_PATH" != "$DYNLIBS_DIR" ]; then
         if [ "$LD_LIBRARY_PATH" != "$DYNLIBS_DIR" ]; then
@@ -349,7 +350,7 @@ if [ "$IS_BOOT_COMMAND" = 'yes' ]; then
         ## Turn off debug, because COMPATIBILITY_INFO needs to capture stderr
         ## Turn off debug, because COMPATIBILITY_INFO needs to capture stderr
         set +x
         set +x
         COMPATIBILITY_INFO="$(compatiblity_info 2>&1 || true)"
         COMPATIBILITY_INFO="$(compatiblity_info 2>&1 || true)"
-        if ! (echo -e "$COMPATIBILITY_INFO" | grep -q 'BEAM_OK'); then
+        if ! (echo -e "$COMPATIBILITY_INFO" | $GREP -q 'BEAM_OK'); then
             ## not able to start beam.smp
             ## not able to start beam.smp
             set +x
             set +x
             logerr "$COMPATIBILITY_INFO"
             logerr "$COMPATIBILITY_INFO"
@@ -358,7 +359,7 @@ if [ "$IS_BOOT_COMMAND" = 'yes' ]; then
             logerr "Version=$REL_VSN"
             logerr "Version=$REL_VSN"
             logerr "Required dependencies: openssl-1.1.1 (libcrypto), libncurses and libatomic1"
             logerr "Required dependencies: openssl-1.1.1 (libcrypto), libncurses and libatomic1"
             exit 1
             exit 1
-        elif ! (echo -e "$COMPATIBILITY_INFO" | grep -q 'CRYPTO_OK'); then
+        elif ! (echo -e "$COMPATIBILITY_INFO" | $GREP -q 'CRYPTO_OK'); then
             ## not able to start crypto app
             ## not able to start crypto app
             set +x
             set +x
             logerr "$COMPATIBILITY_INFO"
             logerr "$COMPATIBILITY_INFO"
@@ -490,22 +491,22 @@ else
     #  * The grep args like '[e]mqx' but not 'emqx' is to avoid greping the grep command itself
     #  * The grep args like '[e]mqx' but not 'emqx' is to avoid greping the grep command itself
     #  * The running 'remsh' and 'nodetool' processes must be excluded
     #  * The running 'remsh' and 'nodetool' processes must be excluded
     # shellcheck disable=SC2009
     # shellcheck disable=SC2009
-    PS_LINE="$(ps -ef | grep '[e]mqx' | grep -v -E '(remsh|nodetool)' | grep -oE "\-[r]oot ${RUNNER_ROOT_DIR}.*" || true)"
+    PS_LINE="$(ps -ef | $GREP '[e]mqx' | $GREP -v -E '(remsh|nodetool)' | $GREP -oE "\-[r]oot ${RUNNER_ROOT_DIR}.*" || true)"
     [ "$DEBUG" -eq 1 ] && echo "EMQX processes: $PS_LINE"
     [ "$DEBUG" -eq 1 ] && echo "EMQX processes: $PS_LINE"
     if [ "$(echo -e "$PS_LINE" | wc -l)" -eq 1 ]; then
     if [ "$(echo -e "$PS_LINE" | wc -l)" -eq 1 ]; then
         ## only one emqx node is running, get running args from 'ps -ef' output
         ## only one emqx node is running, get running args from 'ps -ef' output
-        tmp_nodename=$(echo -e "$PS_LINE" | grep -oE "\s\-s?name.*" | awk '{print $2}' || true)
-        tmp_cookie=$(echo -e "$PS_LINE" | grep -oE "\s\-setcookie.*" | awk '{print $2}' || true)
-        tmp_dist="$(echo -e "$PS_LINE" | grep -oE '\-ssl_dist_optfile\s.+\s' | awk '{print $2}' || true)"
+        tmp_nodename=$(echo -e "$PS_LINE" | $GREP -oE "\s\-s?name.*" | awk '{print $2}' || true)
+        tmp_cookie=$(echo -e "$PS_LINE" | $GREP -oE "\s\-setcookie.*" | awk '{print $2}' || true)
+        tmp_dist="$(echo -e "$PS_LINE" | $GREP -oE '\-ssl_dist_optfile\s.+\s' | awk '{print $2}' || true)"
         # data_dir is actually not needed, but kept anyway
         # data_dir is actually not needed, but kept anyway
-        tmp_daadir="$(echo -e "$PS_LINE" | grep -oE "\-emqx_data_dir.*" | sed -E 's#.+emqx_data_dir[[:blank:]]##g' | sed -E 's#[[:blank:]]--$##g' || true)"
+        tmp_datadir="$(echo -e "$PS_LINE" | $GREP -oE "\-emqx_data_dir.*" | sed -E 's#.+emqx_data_dir[[:blank:]]##g' | sed -E 's#[[:blank:]]--$##g' || true)"
         if [ -z "$tmp_dist" ]; then
         if [ -z "$tmp_dist" ]; then
             tmp_proto='inet_tcp'
             tmp_proto='inet_tcp'
         else
         else
             tmp_proto='inet_tls'
             tmp_proto='inet_tls'
         fi
         fi
         ## Make the format like what call_hocon multi_get prints out, but only need 4 args
         ## Make the format like what call_hocon multi_get prints out, but only need 4 args
-        EMQX_BOOT_CONFIGS="node.name=${tmp_nodename}\nnode.cookie=${tmp_cookie}\ncluster.proto_dist=${tmp_proto}\nnode.data_dir=${tmp_daadir}"
+        EMQX_BOOT_CONFIGS="node.name=${tmp_nodename}\nnode.cookie=${tmp_cookie}\ncluster.proto_dist=${tmp_proto}\nnode.data_dir=${tmp_datadir}"
         [ "$DEBUG" -eq 1 ] && echo "EMQX boot-configs: $EMQX_BOOT_CONFIGS"
         [ "$DEBUG" -eq 1 ] && echo "EMQX boot-configs: $EMQX_BOOT_CONFIGS"
     else
     else
         ## None or more than one node is running, resolve from boot config
         ## None or more than one node is running, resolve from boot config
@@ -517,7 +518,7 @@ fi
 
 
 get_boot_config() {
 get_boot_config() {
     path_to_value="$1"
     path_to_value="$1"
-    echo -e "$EMQX_BOOT_CONFIGS" | grep "$path_to_value=" | sed -e "s/$path_to_value=//g" | tr -d \"
+    echo -e "$EMQX_BOOT_CONFIGS" | $GREP "$path_to_value=" | sed -e "s/$path_to_value=//g" | tr -d \"
 }
 }
 
 
 EPMD_ARGS="-start_epmd false -epmd_module ekka_epmd -proto_dist ekka"
 EPMD_ARGS="-start_epmd false -epmd_module ekka_epmd -proto_dist ekka"
@@ -744,7 +745,7 @@ generate_config() {
         ARG_KEY=$(echo "$ARG_LINE" | awk '{$NF="";print}')
         ARG_KEY=$(echo "$ARG_LINE" | awk '{$NF="";print}')
         ARG_VALUE=$(echo "$ARG_LINE" | awk '{print $NF}')
         ARG_VALUE=$(echo "$ARG_LINE" | awk '{print $NF}')
         ## use the key to look up in vm.args file for the value
         ## use the key to look up in vm.args file for the value
-        TMP_ARG_VALUE=$(grep "^$ARG_KEY" "$TMP_ARG_FILE" || true | awk '{print $NF}')
+        TMP_ARG_VALUE=$($GREP "^$ARG_KEY" "$TMP_ARG_FILE" || true | awk '{print $NF}')
         ## compare generated (to override) value to original (to be overridden) value
         ## compare generated (to override) value to original (to be overridden) value
         if [ "$ARG_VALUE" != "$TMP_ARG_VALUE" ] ; then
         if [ "$ARG_VALUE" != "$TMP_ARG_VALUE" ] ; then
             ## if they are different
             ## if they are different
@@ -769,7 +770,7 @@ is_down() {
     if ps -p "$PID" >/dev/null; then
     if ps -p "$PID" >/dev/null; then
         # still around
         # still around
         # shellcheck disable=SC2009 # this grep pattern is not a part of the progra names
         # shellcheck disable=SC2009 # this grep pattern is not a part of the progra names
-        if ps -p "$PID" | grep -q 'defunct'; then
+        if ps -p "$PID" | $GREP -q 'defunct'; then
             # zombie state, print parent pid
             # zombie state, print parent pid
             parent="$(ps -o ppid= -p "$PID" | tr -d ' ')"
             parent="$(ps -o ppid= -p "$PID" | tr -d ' ')"
             logwarn "$PID is marked <defunct>, parent: $(ps -p "$parent")"
             logwarn "$PID is marked <defunct>, parent: $(ps -p "$parent")"

+ 1 - 1
changes/v5.0.18/fix-9961.en.md

@@ -1 +1 @@
-Avoid parsing config files for node name and cookie when executing non-boot commands in bin/emqx
+Avoid parsing config files for node name and cookie when executing non-boot commands in bin/emqx.

+ 1 - 1
changes/v5.0.18/fix-9961.zh.md

@@ -1 +1 @@
-在 bin/emqx 脚本中,避免在运行非启动命令时解析 emqx.conf 来获取节点名称和 cookie
+在 bin/emqx 脚本中,避免在运行非启动命令时解析 emqx.conf 来获取节点名称和 cookie