sql-gateway.sh 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env bash
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. function usage() {
  20. echo "Usage: sql-gateway.sh [start|start-foreground|stop|stop-all] [args]"
  21. echo " commands:"
  22. echo " start - Run a SQL Gateway as a daemon"
  23. echo " start-foreground - Run a SQL Gateway as a console application"
  24. echo " stop - Stop the SQL Gateway daemon"
  25. echo " stop-all - Stop all the SQL Gateway daemons"
  26. echo " -h | --help - Show this help message"
  27. }
  28. ################################################################################
  29. # Adopted from "flink" bash script
  30. ################################################################################
  31. target="$0"
  32. # For the case, the executable has been directly symlinked, figure out
  33. # the correct bin path by following its symlink up to an upper bound.
  34. # Note: we can't use the readlink utility here if we want to be POSIX
  35. # compatible.
  36. iteration=0
  37. while [ -L "$target" ]; do
  38. if [ "$iteration" -gt 100 ]; then
  39. echo "Cannot resolve path: You have a cyclic symlink in $target."
  40. break
  41. fi
  42. ls=`ls -ld -- "$target"`
  43. target=`expr "$ls" : '.* -> \(.*\)$'`
  44. iteration=$((iteration + 1))
  45. done
  46. # Convert relative path to absolute path
  47. bin=`dirname "$target"`
  48. # get flink config
  49. . "$bin"/config.sh
  50. if [ "$FLINK_IDENT_STRING" = "" ]; then
  51. FLINK_IDENT_STRING="$USER"
  52. fi
  53. ################################################################################
  54. # SQL gateway specific logic
  55. ################################################################################
  56. ENTRYPOINT=sql-gateway
  57. if [[ "$1" = *--help ]] || [[ "$1" = *-h ]]; then
  58. usage
  59. exit 0
  60. fi
  61. STARTSTOP=$1
  62. if [ -z "$STARTSTOP" ]; then
  63. STARTSTOP="start"
  64. fi
  65. if [[ $STARTSTOP != "start" ]] && [[ $STARTSTOP != "start-foreground" ]] && [[ $STARTSTOP != "stop" ]] && [[ $STARTSTOP != "stop-all" ]]; then
  66. usage
  67. exit 1
  68. fi
  69. # ./sql-gateway.sh start --help, print the message to the console
  70. if [[ "$STARTSTOP" = start* ]] && ( [[ "$*" = *--help* ]] || [[ "$*" = *-h* ]] ); then
  71. FLINK_TM_CLASSPATH=`constructFlinkClassPath`
  72. SQL_GATEWAY_CLASSPATH=`findSqlGatewayJar`
  73. "$JAVA_RUN" -classpath "`manglePathList "$FLINK_TM_CLASSPATH:$SQL_GATEWAY_CLASSPATH:$INTERNAL_HADOOP_CLASSPATHS"`" org.apache.flink.table.gateway.SqlGateway "${@:2}"
  74. exit 0
  75. fi
  76. if [[ $STARTSTOP == "start-foreground" ]]; then
  77. exec "${FLINK_BIN_DIR}"/flink-console.sh $ENTRYPOINT "${@:2}"
  78. else
  79. "${FLINK_BIN_DIR}"/flink-daemon.sh $STARTSTOP $ENTRYPOINT "${@:2}"
  80. fi