This is an automated email from the ASF dual-hosted git repository.

mxsm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new 3678c23bd [ISSUE #4398] Use bash to excute shell script and fix 
mis-output (#4401)
3678c23bd is described below

commit 3678c23bdf4bed9522f312a7a25b1951337aa5d5
Author: Pil0tXia <[email protected]>
AuthorDate: Sat Aug 26 22:52:14 2023 +0800

    [ISSUE #4398] Use bash to excute shell script and fix mis-output (#4401)
    
    * fix: dos2unix shell scripts & remove shell gitignore
    
    * fix: use bash instead of sh by default
    
    * fix: Verify if the previous process terminated abnormally for stop.sh
    
    * fix: Verify if the previous process terminated abnormally for start.sh 
and optimize output
    
    * Optimize: Standardise shell syntax
---
 .gitignore                     |  3 +--
 eventmesh-runtime/bin/start.sh | 33 ++++++++++++++++++++++-----------
 eventmesh-runtime/bin/stop.sh  | 23 +++++++++++++++++------
 3 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/.gitignore b/.gitignore
index efc571d27..e75f1a127 100644
--- a/.gitignore
+++ b/.gitignore
@@ -47,5 +47,4 @@ bld/
 [Bb]in/
 [Oo]bj/
 [Ll]og/
-[Ll]ogs/
-!eventmesh-runtime/bin/*.sh
\ No newline at end of file
+[Ll]ogs/
\ No newline at end of file
diff --git a/eventmesh-runtime/bin/start.sh b/eventmesh-runtime/bin/start.sh
index 3ad63a71e..1e2099db9 100644
--- a/eventmesh-runtime/bin/start.sh
+++ b/eventmesh-runtime/bin/start.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # Licensed to Apache Software Foundation (ASF) under one or more contributor
 # license agreements. See the NOTICE file distributed with
@@ -53,6 +53,13 @@ function get_pid {
        local ppid=""
        if [ -f ${EVENTMESH_HOME}/bin/pid.file ]; then
                ppid=$(cat ${EVENTMESH_HOME}/bin/pid.file)
+               # If the process does not exist, it indicates that the previous 
process terminated abnormally.
+    if [ ! -d /proc/$ppid ]; then
+      # Remove the residual file
+      rm ${EVENTMESH_HOME}/bin/pid.file
+      echo -e "ERROR\t EventMesh process had already terminated unexpectedly 
before, please check log output."
+      ppid=""
+    fi
        else
                if [[ $OS =~ Msys ]]; then
                        # There is a Bug on Msys that may not be able to kill 
the identified process
@@ -82,19 +89,19 @@ elif  is_java8 "/nemo/jdk/bin/java"; then
 elif is_java8 "$(which java)"; then
         JAVA="$(which java)"
 else
-        echo -e "ERROR\t java(1.8) not found, operation abort."
+        echo -e "ERROR\t Java 8 not found, operation abort."
         exit 9;
 fi
 
-echo "eventmesh use java location= "$JAVA
-
-EVENTMESH_HOME=`cd $(dirname $0)/.. && pwd`
+echo "EventMesh use Java location: $JAVA"
 
+EVENTMESH_HOME=$(cd "$(dirname "$0")/.." && pwd)
 export EVENTMESH_HOME
 
-export EVENTMESH_LOG_HOME=${EVENTMESH_HOME}/logs
+EVENTMESH_LOG_HOME="${EVENTMESH_HOME}/logs"
+export EVENTMESH_LOG_HOME
 
-echo "EVENTMESH_HOME : ${EVENTMESH_HOME}, EVENTMESH_LOG_HOME : 
${EVENTMESH_LOG_HOME}"
+echo -e "EVENTMESH_HOME : ${EVENTMESH_HOME}\nEVENTMESH_LOG_HOME : 
${EVENTMESH_LOG_HOME}"
 
 function make_logs_dir {
         if [ ! -e "${EVENTMESH_LOG_HOME}" ]; then mkdir -p 
"${EVENTMESH_LOG_HOME}"; fi
@@ -102,7 +109,7 @@ function make_logs_dir {
 
 error_exit ()
 {
-    echo "ERROR: $1 !!"
+    echo -e "ERROR\t $1 !!"
     exit 1
 }
 
@@ -148,14 +155,18 @@ JAVA_OPT="${JAVA_OPT} 
-DeventMeshPluginDir=${EVENTMESH_HOME}/plugin"
 #fi
 
 pid=$(get_pid)
+if [[ $pid == "ERROR"* ]]; then
+  echo -e "${pid}"
+  exit 9
+fi
 if [ -n "$pid" ];then
-       echo -e "ERROR\t the server is already running (pid=$pid), there is no 
need to execute start.sh again."
-       exit 9;
+       echo -e "ERROR\t The server is already running (pid=$pid), there is no 
need to execute start.sh again."
+       exit 9
 fi
 
 make_logs_dir
 
-echo "using jdk[$JAVA]" >> ${EVENTMESH_LOG_HOME}/eventmesh.out
+echo "Using JDK[$JAVA]" >> ${EVENTMESH_LOG_HOME}/eventmesh.out
 
 
 EVENTMESH_MAIN=org.apache.eventmesh.runtime.boot.EventMeshStartup
diff --git a/eventmesh-runtime/bin/stop.sh b/eventmesh-runtime/bin/stop.sh
index e85fbf5ec..b4f1d0015 100644
--- a/eventmesh-runtime/bin/stop.sh
+++ b/eventmesh-runtime/bin/stop.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # Licensed to Apache Software Foundation (ASF) under one or more contributor
 # license agreements. See the NOTICE file distributed with
@@ -17,7 +17,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
-#detect operating system.
+# Detect operating system
 OS=$(uname)
 
 EVENTMESH_HOME=`cd $(dirname $0)/.. && pwd`
@@ -28,6 +28,13 @@ function get_pid {
        local ppid=""
        if [ -f ${EVENTMESH_HOME}/bin/pid.file ]; then
                ppid=$(cat ${EVENTMESH_HOME}/bin/pid.file)
+    # If the process does not exist, it indicates that the previous process 
terminated abnormally.
+    if [ ! -d /proc/$ppid ]; then
+      # Remove the residual file and return an error status.
+      rm ${EVENTMESH_HOME}/bin/pid.file
+      echo -e "ERROR\t EventMesh process had already terminated unexpectedly 
before, please check log output."
+      ppid=""
+    fi
        else
                if [[ $OS =~ Msys ]]; then
                        # There is a Bug on Msys that may not be able to kill 
the identified process
@@ -44,20 +51,24 @@ function get_pid {
 }
 
 pid=$(get_pid)
+if [[ $pid == "ERROR"* ]]; then
+  echo -e "${pid}"
+  exit 9
+fi
 if [ -z "$pid" ];then
-       echo -e "No eventmesh running.."
-       exit 0;
+       echo -e "ERROR\t No EventMesh server running."
+       exit 9
 fi
 
 kill ${pid}
-echo "Send shutdown request to eventmesh(${pid}) OK"
+echo "Send shutdown request to EventMesh(${pid}) OK"
 
 [[ $OS =~ Msys ]] && PS_PARAM=" -W "
 stop_timeout=60
 for no in $(seq 1 $stop_timeout); do
        if ps $PS_PARAM -p "$pid" 2>&1 > /dev/null; then
                if [ $no -lt $stop_timeout ]; then
-                       echo "[$no] shutdown server ..."
+                       echo "[$no] server shutting down ..."
                        sleep 1
                        continue
                fi


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to