【flink脚本系列】 sql-gateway.sh功能用法示例源码详解

flink脚本系列 SQL Gateway脚本

脚本主要功能

该脚本用于启动和停止SQL Gateway。以下是脚本的主要功能:

  • 提供了脚本使用说明的usage函数。
  • 解析命令行参数,包括启动或停止命令、帮助参数等。
  • 根据不同的命令执行相应的操作,如以后台或前台方式启动SQL Gateway,停止SQL Gateway等。
  • 引入其他依赖脚本和配置文件,获取相关配置信息。

脚本加上中文注释

#!/bin/bash

# 定义脚本使用说明函数
function usage() {
  echo "Usage: sql-gateway.sh [start|start-foreground|stop|stop-all] [args]"
  echo "  commands:"
  echo "    start               - Run a SQL Gateway as a daemon"
  echo "    start-foreground    - Run a SQL Gateway as a console application"
  echo "    stop                - Stop the SQL Gateway daemon"
  echo "    stop-all            - Stop all the SQL Gateway daemons"
  echo "    -h | --help         - Show this help message"
}

################################################################################
# 从 "flink" bash 脚本中采用的部分
################################################################################

target="$0"
# 如果可执行文件直接进行了符号链接,通过迭代解析符号链接的正确路径
iteration=0
while [ -L "$target" ]; do
    if [ "$iteration" -gt 100 ]; then
        echo "Cannot resolve path: You have a cyclic symlink in $target."
        break
    fi
    ls=`ls -ld -- "$target"`
    target=`expr "$ls" : '.* -> \(.*\)$'`
    iteration=$((iteration + 1))
done

# 转换相对路径为绝对路径
bin=`dirname "$target"`

# 导入flink配置
. "$bin"/config.sh

if [ "$FLINK_IDENT_STRING" = "" ]; then
        FLINK_IDENT_STRING="$USER"
fi

################################################################################
# SQL gateway 特定逻辑
################################################################################

ENTRYPOINT=sql-gateway

# 如果命令行参数包含--help或-h,则打印使用说明并退出
if [[ "$1" = *--help ]] || [[ "$1" = *-h ]]; then
  usage
  exit 0
fi

STARTSTOP=$1

# 如果未提供启动或停止命令,则默认为"start"
if [ -z "$STARTSTOP" ]; then
  STARTSTOP="start"
fi

# 如果提供的命令不是有效的启动或停止命令,则打印使用说明并退出
if [[ $STARTSTOP != "start" ]] && [[ $STARTSTOP != "start-foreground" ]] && [[ $STARTSTOP != "stop" ]] && [[ $STARTSTOP != "stop-all" ]]; then
  usage
  exit 1
fi

# 如果命令是"start*",并且包含--help或-h参数,则以前台方式打印帮助信息到控制台并退出
if [[ "$STARTSTOP" = start* ]] && ( [[ "$*" = *--help* ]] || [[ "$*" = *-h* ]] ); then
  FLINK_TM_CLASSPATH=`constructFlinkClassPath`
  SQL_GATEWAY_CLASSPATH=`findSqlGatewayJar`
  "$JAVA_RUN"  -classpath "`manglePathList "$FLINK_TM_CLASSPATH:$SQL_GATEWAY_CLASSPATH:$INTERNAL_HADOOP_CLASSPATHS"`" org.apache.flink.table.gateway.SqlGateway "${@:2}"
  exit 0
fi

# 如果命令是"start-foreground",则以前台方式执行flink-console.sh脚本启动SQL Gateway
if [[ $STARTSTOP == "start-foreground" ]]; then
    exec "${FLINK_BIN_DIR}"/flink-console.sh $ENTRYPOINT "${@:2}"
else
    # 否则,使用flink-daemon.sh脚本以后台方式启动或停止SQL Gateway
    "${FLINK_BIN_DIR}"/flink-daemon.sh $STARTSTOP $ENTRYPOINT "${@:2}"
fi

该脚本多种用法及其代码示例

该脚本支持以下多种用法和相应的代码示例:

  1. 启动SQL Gateway作为守护进程:

    ./sql-gateway.sh start
    
  2. 启动SQL Gateway作为控制台应用程序:

    ./sql-gateway.sh start-foreground
    
  3. 停止SQL Gateway守护进程:

    ./sql-gateway.sh stop
    
  4. 停止所有SQL Gateway守护进程:

    ./sql-gateway.sh stop-all
    
  5. 打印帮助信息:

    ./sql-gateway.sh --help
    

官方链接

您可以在以下链接中找到有关该脚本的更多信息:

Gateway官方链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BigDataMLApplication

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值