This is an automated email from the ASF dual-hosted git repository. benjobs pushed a commit to branch docker-push in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
commit e489cf424780991bbefc73a78dd5cfad9dd165b3 Author: benjobs <[email protected]> AuthorDate: Tue Apr 9 23:16:41 2024 +0800 [Improve] shell script improvement --- .github/workflows/docker-push.yml | 2 +- .../src/main/assembly/bin/setclasspath.sh | 22 +++++------ .../src/main/assembly/bin/shutdown.sh | 2 +- .../src/main/assembly/bin/startup.sh | 2 +- .../src/main/assembly/bin/streampark.sh | 45 +++++++++++----------- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 4a70cc72e..70034b6f2 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -75,7 +75,7 @@ jobs: with: images: apache/streampark tags: | - type=semver,pattern={{version}} + type=match,pattern=release-/v(.*),group=1 - name: Build and push image uses: docker/build-push-action@v3 diff --git a/streampark-console/streampark-console-service/src/main/assembly/bin/setclasspath.sh b/streampark-console/streampark-console-service/src/main/assembly/bin/setclasspath.sh index c99c30c1c..68fb48227 100755 --- a/streampark-console/streampark-console-service/src/main/assembly/bin/setclasspath.sh +++ b/streampark-console/streampark-console-service/src/main/assembly/bin/setclasspath.sh @@ -23,40 +23,40 @@ # ----------------------------------------------------------------------------- # Make sure prerequisite environment variables are set -if [ -z "$JAVA_HOME" ] && [ -z "$JRE_HOME" ]; then +if [[ -z "$JAVA_HOME" ]] && [[ -z "$JRE_HOME" ]]; then # shellcheck disable=SC2154 if $darwin; then # Bugzilla 54390 - if [ -x '/usr/libexec/java_home' ] ; then + if [[ -x '/usr/libexec/java_home' ]] ; then # shellcheck disable=SC2155 export JAVA_HOME=$(/usr/libexec/java_home) # Bugzilla 37284 (reviewed). - elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then + elif [[ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]]; then export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" fi else JAVA_PATH=$(which java 2>/dev/null) - if [ "x$JAVA_PATH" != "x" ]; then + if [[ "x$JAVA_PATH" != "x" ]]; then JAVA_PATH=$(dirname "$JAVA_PATH" 2>/dev/null) JRE_HOME=$(dirname "$JAVA_PATH" 2>/dev/null) fi - if [ "x$JRE_HOME" = "x" ]; then + if [[ "x$JRE_HOME" = "x" ]]; then # XXX: Should we try other locations? - if [ -x /usr/bin/java ]; then + if [[ -x /usr/bin/java ]]; then JRE_HOME=/usr fi fi fi - if [ -z "$JAVA_HOME" ] && [ -z "$JRE_HOME" ]; then + if [[ -z "$JAVA_HOME" ]] && [[ -z "$JRE_HOME" ]]; then echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined" echo "At least one of these environment variable is needed to run this program" exit 1 fi fi -if [ -z "$JRE_HOME" ]; then +if [[ -z "$JRE_HOME" ]]; then # JAVA_HOME_MUST be set - if [ ! -x "$JAVA_HOME"/bin/java ]; then + if [[ ! -x "$JAVA_HOME"/bin/java ]]; then echo "The JAVA_HOME environment variable is not defined correctly" echo "JAVA_HOME=$JAVA_HOME" echo "This environment variable is needed to run this program" @@ -65,7 +65,7 @@ if [ -z "$JRE_HOME" ]; then fi JRE_HOME="$JAVA_HOME" else - if [ ! -x "$JRE_HOME"/bin/java ]; then + if [[ ! -x "$JRE_HOME"/bin/java ]]; then echo "The JRE_HOME environment variable is not defined correctly" echo "JRE_HOME=$JRE_HOME" echo "This environment variable is needed to run this program" @@ -74,6 +74,6 @@ else fi # Set standard commands for invoking Java, if not already set. -if [ -z "$_RUNJAVA" ]; then +if [[ -z "$_RUNJAVA" ]]; then _RUNJAVA="$JRE_HOME"/bin/java fi diff --git a/streampark-console/streampark-console-service/src/main/assembly/bin/shutdown.sh b/streampark-console/streampark-console-service/src/main/assembly/bin/shutdown.sh index 6d77311be..a42454d56 100755 --- a/streampark-console/streampark-console-service/src/main/assembly/bin/shutdown.sh +++ b/streampark-console/streampark-console-service/src/main/assembly/bin/shutdown.sh @@ -46,7 +46,7 @@ if $os400; then # this will not work if the user belongs in secondary groups eval else - if [ ! -x "$PRG_DIR"/"$EXECUTABLE" ]; then + if [[ ! -x "$PRG_DIR"/"$EXECUTABLE" ]]; then echo "Cannot find $PRG_DIR/$EXECUTABLE" echo "The file is absent or does not have execute permission" echo "This file is needed to run this program" diff --git a/streampark-console/streampark-console-service/src/main/assembly/bin/startup.sh b/streampark-console/streampark-console-service/src/main/assembly/bin/startup.sh index 6bec60931..a900d8979 100755 --- a/streampark-console/streampark-console-service/src/main/assembly/bin/startup.sh +++ b/streampark-console/streampark-console-service/src/main/assembly/bin/startup.sh @@ -52,7 +52,7 @@ if $os400; then # this will not work if the user belongs in secondary groups eval else - if [ ! -x "$PRG_DIR"/"$EXECUTABLE" ]; then + if [[ ! -x "$PRG_DIR"/"$EXECUTABLE" ]]; then echo "Cannot find $PRG_DIR/$EXECUTABLE" echo "The file is absent or does not have execute permission" echo "This file is needed to run this program" diff --git a/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh b/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh index 4bfbaf89b..ec6adeec7 100755 --- a/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh +++ b/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh @@ -210,7 +210,7 @@ fi # Add on extra jar files to CLASSPATH # shellcheck disable=SC2236 -if [ ! -z "$CLASSPATH" ]; then +if [[ ! -z "$CLASSPATH" ]]; then CLASSPATH="$CLASSPATH": fi CLASSPATH="$CLASSPATH" @@ -229,7 +229,7 @@ if ${cygwin}; then CLASSPATH=`cygpath --path --windows "$CLASSPATH"` fi -if [ -z "$USE_NOHUP" ]; then +if [[ -z "$USE_NOHUP" ]]; then if $hpux; then USE_NOHUP="true" else @@ -237,7 +237,7 @@ if [ -z "$USE_NOHUP" ]; then fi fi unset NOHUP -if [ "$USE_NOHUP" = "true" ]; then +if [[ "$USE_NOHUP" = "true" ]]; then NOHUP="nohup" fi @@ -248,7 +248,7 @@ APP_MAIN="org.apache.streampark.console.StreamParkConsoleBootstrap" JVM_OPTS_FILE=${APP_HOME}/bin/jvm_opts.sh JVM_ARGS="" -if [ -f $JVM_OPTS_FILE ]; then +if [[ -f $JVM_OPTS_FILE ]]; then while read line do if [[ "$line" == -* ]]; then @@ -296,14 +296,14 @@ init_env() { # shellcheck disable=SC2120 get_pid() { - if [ -f "$APP_PID" ]; then - if [ -s "$APP_PID" ]; then + if [[ -f "$APP_PID" ]]; then + if [[ -s "$APP_PID" ]]; then # shellcheck disable=SC2155 # shellcheck disable=SC2006 local PID=`cat "$APP_PID"` kill -0 $PID >/dev/null 2>&1 # shellcheck disable=SC2181 - if [ $? -eq 0 ]; then + if [[ $? -eq 0 ]]; then echo $PID exit 0 fi @@ -314,17 +314,17 @@ get_pid() { # shellcheck disable=SC2006 local serverPort=`$_RUNJAVA -cp "$APP_LIB/*" $BASH_UTIL --yaml "server.port" "$CONFIG"` - if [ x"${serverPort}" == x"" ]; then + if [[ x"${serverPort}" == x"" ]]; then echo_r "server.port is required, please check $CONFIG" exit 1; else # shellcheck disable=SC2006 # shellcheck disable=SC2155 local used=`lsof -i:"$serverPort" | wc -l` - if [ "$used" -gt 0 ]; then + if [[ "$used" -gt 0 ]]; then # shellcheck disable=SC2006 local PID=`jps -l | grep "$APP_MAIN" | awk '{print $1}'` - if [ ! -z $PID ]; then + if [[ ! -z $PID ]]; then echo $PID else echo 0 @@ -340,7 +340,7 @@ start() { # shellcheck disable=SC2006 local PID=$(get_pid) - if [ $PID -gt 0 ]; then + if [[ $PID -gt 0 ]]; then # shellcheck disable=SC2006 echo_r "StreamPark is already running pid: $PID , start aborted!" exit 1 @@ -371,7 +371,7 @@ start() { exit 1; fi - if [ "${HADOOP_HOME}"x == ""x ]; then + if [[ "${HADOOP_HOME}"x == ""x ]]; then echo_y "WARN: HADOOP_HOME is undefined on your system env,please check it." else echo_w "Using HADOOP_HOME: ${HADOOP_HOME}" @@ -441,7 +441,7 @@ start_docker() { echo_w "Using APP_PID: $APP_PID" fi - if [ "${HADOOP_HOME}"x == ""x ]; then + if [[ "${HADOOP_HOME}"x == ""x ]]; then echo_y "WARN: HADOOP_HOME is undefined on your system env,please check it." else echo_w "Using HADOOP_HOME: ${HADOOP_HOME}" @@ -484,7 +484,8 @@ start_docker() { } debug() { - if [ ! -n "$DEBUG_PORT" ]; then + # shellcheck disable=SC2236 + if [[ ! -n "$DEBUG_PORT" ]]; then echo_r "If start with debug mode,Please fill in the debug port like: bash streampark.sh debug 10002 " else DEBUG_OPTS=""" @@ -512,17 +513,17 @@ stop() { # shellcheck disable=SC2006 echo_g "StreamPark stopping with the PID: $PID" - kill -9 $PID + kill -9 "$PID" while [ $SLEEP -ge 0 ]; do # shellcheck disable=SC2046 # shellcheck disable=SC2006 - kill -0 $PID >/dev/null 2>&1 + kill -0 "$PID" >/dev/null 2>&1 # shellcheck disable=SC2181 - if [ $? -gt 0 ]; then + if [[ $? -gt 0 ]]; then rm -f "$APP_PID" >/dev/null 2>&1 - if [ $? != 0 ]; then - if [ -w "$APP_PID" ]; then + if [[ $? != 0 ]]; then + if [[ -w "$APP_PID" ]]; then cat /dev/null > "$APP_PID" else echo_r "The PID file could not be removed." @@ -532,7 +533,7 @@ stop() { break fi - if [ $SLEEP -gt 0 ]; then + if [[ $SLEEP -gt 0 ]]; then sleep 1 fi # shellcheck disable=SC2006 @@ -540,7 +541,7 @@ stop() { SLEEP=`expr $SLEEP - 1 ` done - if [ "$SLEEP" -lt 0 ]; then + if [[ "$SLEEP" -lt 0 ]]; then echo_r "StreamPark has not been killed completely yet. The process might be waiting on some system call or might be UNINTERRUPTIBLE." fi } @@ -549,7 +550,7 @@ status() { # shellcheck disable=SC2155 # shellcheck disable=SC2006 local PID=$(get_pid) - if [ $PID -eq 0 ]; then + if [[ $PID -eq 0 ]]; then echo_r "StreamPark is not running" else echo_g "StreamPark is running pid is: $PID"
