You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/08/09 15:14:22 UTC

[GitHub] [shardingsphere] sunkai-cai opened a new pull request, #20038: Enhance startup script

sunkai-cai opened a new pull request, #20038:
URL: https://github.com/apache/shardingsphere/pull/20038

   Fixes #15663.
   
   Changes proposed in this pull request:
   - Refactor the script
   - Priority use java from JAVA_HOME 
   - Check if the address and port which we attempt to use in new Proxy process is already used by another Proxy
   - Judge startup succeeded or failed
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] TeslaCN commented on pull request #20038: Enhance startup script

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on PR #20038:
URL: https://github.com/apache/shardingsphere/pull/20038#issuecomment-1214553856

   There are many cases should be considered in address and port checking. Maybe we could do the checking in next PR. This PR just focus on enhancements about Docker and JAVA_HOME.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #20038: Enhance startup script

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on code in PR #20038:
URL: https://github.com/apache/shardingsphere/pull/20038#discussion_r941938295


##########
shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.sh:
##########
@@ -137,12 +156,57 @@ if [ -z "$PORT" ]; then
 fi
 
 CLASS_PATH=${CONF_PATH}:${CLASS_PATH}
-MAIN_CLASS=${MAIN_CLASS}" "${PORT}" "${CONF_PATH}" "${ADDRESSES}
+MAIN_CLASS="${MAIN_CLASS} ${PORT} ${CONF_PATH} ${ADDRESSES}"
+
+if [ $PORT = -1 ]; then
+  REAL_PORT=3307
+else
+  REAL_PORT=$PORT
+fi
 
-echo "Starting the $SERVER_NAME ..."
 echo "The classpath is ${CLASS_PATH}"
 echo "main class ${MAIN_CLASS}"
-
-nohup java ${JAVA_OPTS} ${JAVA_MEM_OPTS} -classpath ${CLASS_PATH} ${MAIN_CLASS} >> ${STDOUT_FILE} 2>&1 &
-sleep 1
-echo "Please check the STDOUT file: $STDOUT_FILE"
+echo "STDOUT log file: $STDOUT_FILE"
+echo -e "Starting the $SERVER_NAME ...\c"
+
+for((i=1;i<=10;i++)); do
+  if [ "$i" = "10" ]; then
+    echo "failed: Address already in use"
+    exit
+  fi
+
+  PORT_STATUS=$(netstat -ant |$GREP $REAL_PORT |$GREP LISTEN)
+  if [ -n "$PORT_STATUS" ]; then
+    echo -e ".\c"
+    sleep 1
+  else
+    break
+  fi
+done
+echo ""
+
+nohup $JAVA ${JAVA_OPTS} ${JAVA_MEM_OPTS} -classpath ${CLASS_PATH} ${MAIN_CLASS} >> ${STDOUT_FILE} 2>&1 &
+if [ $? -eq 0 ]; then
+  case "$OSTYPE" in
+  *solaris*)
+    pid=$(/bin/echo "${!}\\c")
+    ;;
+  *)
+    pid=$(/bin/echo -n $!)
+    ;;
+  esac
+  if [ $? -eq 0 ]; then
+    sleep 1
+    if ps -p "${pid}" > /dev/null 2>&1; then
+      echo "SUCCESS, PID: $pid"
+      exit 0
+    else
+      echo "FAILED TO START"
+    fi
+  else
+    echo "FAILED TO GET PID"
+  fi
+else
+  echo "SERVER DID NOT START"
+fi
+exit 1

Review Comment:
   Does it work in Docker?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #20038: Enhance startup script

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on code in PR #20038:
URL: https://github.com/apache/shardingsphere/pull/20038#discussion_r941936986


##########
shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.sh:
##########
@@ -137,12 +156,57 @@ if [ -z "$PORT" ]; then
 fi
 
 CLASS_PATH=${CONF_PATH}:${CLASS_PATH}
-MAIN_CLASS=${MAIN_CLASS}" "${PORT}" "${CONF_PATH}" "${ADDRESSES}
+MAIN_CLASS="${MAIN_CLASS} ${PORT} ${CONF_PATH} ${ADDRESSES}"
+
+if [ $PORT = -1 ]; then
+  REAL_PORT=3307
+else
+  REAL_PORT=$PORT
+fi
 
-echo "Starting the $SERVER_NAME ..."
 echo "The classpath is ${CLASS_PATH}"
 echo "main class ${MAIN_CLASS}"
-
-nohup java ${JAVA_OPTS} ${JAVA_MEM_OPTS} -classpath ${CLASS_PATH} ${MAIN_CLASS} >> ${STDOUT_FILE} 2>&1 &
-sleep 1
-echo "Please check the STDOUT file: $STDOUT_FILE"
+echo "STDOUT log file: $STDOUT_FILE"
+echo -e "Starting the $SERVER_NAME ...\c"
+
+for((i=1;i<=10;i++)); do
+  if [ "$i" = "10" ]; then
+    echo "failed: Address already in use"
+    exit
+  fi
+
+  PORT_STATUS=$(netstat -ant |$GREP $REAL_PORT |$GREP LISTEN)

Review Comment:
   ShardingSphere-Proxy could listen on specified address such as `192.168.0.1/red`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #20038: Enhance startup script

Posted by GitBox <gi...@apache.org>.
sunkai-cai commented on code in PR #20038:
URL: https://github.com/apache/shardingsphere/pull/20038#discussion_r942577824


##########
shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.sh:
##########
@@ -137,12 +156,57 @@ if [ -z "$PORT" ]; then
 fi
 
 CLASS_PATH=${CONF_PATH}:${CLASS_PATH}
-MAIN_CLASS=${MAIN_CLASS}" "${PORT}" "${CONF_PATH}" "${ADDRESSES}
+MAIN_CLASS="${MAIN_CLASS} ${PORT} ${CONF_PATH} ${ADDRESSES}"
+
+if [ $PORT = -1 ]; then
+  REAL_PORT=3307
+else
+  REAL_PORT=$PORT
+fi
 
-echo "Starting the $SERVER_NAME ..."
 echo "The classpath is ${CLASS_PATH}"
 echo "main class ${MAIN_CLASS}"
-
-nohup java ${JAVA_OPTS} ${JAVA_MEM_OPTS} -classpath ${CLASS_PATH} ${MAIN_CLASS} >> ${STDOUT_FILE} 2>&1 &
-sleep 1
-echo "Please check the STDOUT file: $STDOUT_FILE"
+echo "STDOUT log file: $STDOUT_FILE"
+echo -e "Starting the $SERVER_NAME ...\c"
+
+for((i=1;i<=10;i++)); do
+  if [ "$i" = "10" ]; then
+    echo "failed: Address already in use"
+    exit
+  fi
+
+  PORT_STATUS=$(netstat -ant |$GREP $REAL_PORT |$GREP LISTEN)
+  if [ -n "$PORT_STATUS" ]; then
+    echo -e ".\c"
+    sleep 1
+  else
+    break
+  fi
+done
+echo ""
+
+nohup $JAVA ${JAVA_OPTS} ${JAVA_MEM_OPTS} -classpath ${CLASS_PATH} ${MAIN_CLASS} >> ${STDOUT_FILE} 2>&1 &
+if [ $? -eq 0 ]; then
+  case "$OSTYPE" in
+  *solaris*)
+    pid=$(/bin/echo "${!}\\c")
+    ;;
+  *)
+    pid=$(/bin/echo -n $!)
+    ;;
+  esac
+  if [ $? -eq 0 ]; then
+    sleep 1
+    if ps -p "${pid}" > /dev/null 2>&1; then
+      echo "SUCCESS, PID: $pid"
+      exit 0
+    else
+      echo "FAILED TO START"
+    fi
+  else
+    echo "FAILED TO GET PID"
+  fi
+else
+  echo "SERVER DID NOT START"
+fi
+exit 1

Review Comment:
   ok,work in Docker is done。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sunkai-cai commented on pull request #20038: Enhance startup script

Posted by GitBox <gi...@apache.org>.
sunkai-cai commented on PR #20038:
URL: https://github.com/apache/shardingsphere/pull/20038#issuecomment-1212075847

   thanks @TeslaCN ,This is a good case。 I fix it to support  mulit-ip for start.sh


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #20038: Enhance startup script

Posted by GitBox <gi...@apache.org>.
sunkai-cai commented on code in PR #20038:
URL: https://github.com/apache/shardingsphere/pull/20038#discussion_r941948806


##########
shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.sh:
##########
@@ -137,12 +156,57 @@ if [ -z "$PORT" ]; then
 fi
 
 CLASS_PATH=${CONF_PATH}:${CLASS_PATH}
-MAIN_CLASS=${MAIN_CLASS}" "${PORT}" "${CONF_PATH}" "${ADDRESSES}
+MAIN_CLASS="${MAIN_CLASS} ${PORT} ${CONF_PATH} ${ADDRESSES}"
+
+if [ $PORT = -1 ]; then
+  REAL_PORT=3307
+else
+  REAL_PORT=$PORT
+fi
 
-echo "Starting the $SERVER_NAME ..."
 echo "The classpath is ${CLASS_PATH}"
 echo "main class ${MAIN_CLASS}"
-
-nohup java ${JAVA_OPTS} ${JAVA_MEM_OPTS} -classpath ${CLASS_PATH} ${MAIN_CLASS} >> ${STDOUT_FILE} 2>&1 &
-sleep 1
-echo "Please check the STDOUT file: $STDOUT_FILE"
+echo "STDOUT log file: $STDOUT_FILE"
+echo -e "Starting the $SERVER_NAME ...\c"
+
+for((i=1;i<=10;i++)); do
+  if [ "$i" = "10" ]; then
+    echo "failed: Address already in use"
+    exit
+  fi
+
+  PORT_STATUS=$(netstat -ant |$GREP $REAL_PORT |$GREP LISTEN)
+  if [ -n "$PORT_STATUS" ]; then
+    echo -e ".\c"
+    sleep 1
+  else
+    break
+  fi
+done
+echo ""
+
+nohup $JAVA ${JAVA_OPTS} ${JAVA_MEM_OPTS} -classpath ${CLASS_PATH} ${MAIN_CLASS} >> ${STDOUT_FILE} 2>&1 &
+if [ $? -eq 0 ]; then
+  case "$OSTYPE" in
+  *solaris*)
+    pid=$(/bin/echo "${!}\\c")
+    ;;
+  *)
+    pid=$(/bin/echo -n $!)
+    ;;
+  esac
+  if [ $? -eq 0 ]; then
+    sleep 1
+    if ps -p "${pid}" > /dev/null 2>&1; then
+      echo "SUCCESS, PID: $pid"
+      exit 0
+    else
+      echo "FAILED TO START"
+    fi
+  else
+    echo "FAILED TO GET PID"
+  fi
+else
+  echo "SERVER DID NOT START"
+fi
+exit 1

Review Comment:
   i try it as soon



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #20038: Enhance startup script

Posted by GitBox <gi...@apache.org>.
sunkai-cai commented on code in PR #20038:
URL: https://github.com/apache/shardingsphere/pull/20038#discussion_r941949512


##########
shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.sh:
##########
@@ -137,12 +156,57 @@ if [ -z "$PORT" ]; then
 fi
 
 CLASS_PATH=${CONF_PATH}:${CLASS_PATH}
-MAIN_CLASS=${MAIN_CLASS}" "${PORT}" "${CONF_PATH}" "${ADDRESSES}
+MAIN_CLASS="${MAIN_CLASS} ${PORT} ${CONF_PATH} ${ADDRESSES}"
+
+if [ $PORT = -1 ]; then
+  REAL_PORT=3307
+else
+  REAL_PORT=$PORT
+fi
 
-echo "Starting the $SERVER_NAME ..."
 echo "The classpath is ${CLASS_PATH}"
 echo "main class ${MAIN_CLASS}"
-
-nohup java ${JAVA_OPTS} ${JAVA_MEM_OPTS} -classpath ${CLASS_PATH} ${MAIN_CLASS} >> ${STDOUT_FILE} 2>&1 &
-sleep 1
-echo "Please check the STDOUT file: $STDOUT_FILE"
+echo "STDOUT log file: $STDOUT_FILE"
+echo -e "Starting the $SERVER_NAME ...\c"
+
+for((i=1;i<=10;i++)); do
+  if [ "$i" = "10" ]; then
+    echo "failed: Address already in use"
+    exit
+  fi
+
+  PORT_STATUS=$(netstat -ant |$GREP $REAL_PORT |$GREP LISTEN)

Review Comment:
   ok, i fix it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sunkai-cai commented on pull request #20038: Enhance startup script

Posted by GitBox <gi...@apache.org>.
sunkai-cai commented on PR #20038:
URL: https://github.com/apache/shardingsphere/pull/20038#issuecomment-1211484676

   > How about echoing some warning instead of exiting if addresses & port checking failed? I'm not sure whether the checking could cover all cases.
   
   this a good idea. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] TeslaCN commented on pull request #20038: Enhance startup script

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on PR #20038:
URL: https://github.com/apache/shardingsphere/pull/20038#issuecomment-1211477971

   How about echoing some warning instead of exiting if addresses & port checking failed? I'm not sure whether the checking could cover all cases.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] TeslaCN merged pull request #20038: Enhance startup script

Posted by GitBox <gi...@apache.org>.
TeslaCN merged PR #20038:
URL: https://github.com/apache/shardingsphere/pull/20038


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org