Hive 服务管理脚本

shell 复制代码
#!/bin/bash
HIVE_HOME='/opt/software/hive-3.1.3'
HIVE_LOG_HOME='/opt/software/hive-3.1.3/log'

function checkLogDir {
	if [[ ! -e ${HIVE_LOG_HOME} ]]; then
		echo "${HIVE_LOG_HOME} 目录不存在,正在创建。"
		mkdir -p ${HIVE_LOG_HOME}
	fi
}

function checkHiveMetaStoreProgess {
	metastore=`ps -ef | grep -n HiveMetaStore | grep -v grep | awk '{print $2}'`
	if [[ ! -z ${metastore} ]]; then
		return 1
	else
		return 0
	fi
}

function checkHiveServer2Progess {
	hiveserver2=`ps -ef | grep -n HiveServer2 | grep -v grep | awk '{print $2}'`
	if [[ ! -z ${hiveserver2} ]]; then
		return 1
	else
		return 0
	fi
}

function stopProgess {
	checkHiveMetaStoreProgess
	metastore=`ps -ef | grep -n HiveMetaStore | grep -v grep | awk '{print $2}'`
	if [[ ! -z ${metastore} ]]; then
		echo "HIVE HiveMetaStore 正在停止..."
		kill ${metastore}
	else
		echo "HIVE HiveMetaStore 服务未正常运行"
	fi

	checkHiveServer2Progess
	hiveserver2=`ps -ef | grep -n HiveServer2 | grep -v grep | awk '{print $2}'`
	if [[ ! -z ${hiveserver2} ]]; then
		echo "HIVE HiveServer2 正在停止..."
		kill ${hiveserver2}
	else
		echo "HIVE HiveServer2 服务未正常运行"
	fi
}

function startProgess {
	checkLogDir
		if [[ $? -eq 0 ]]; then
			checkHiveMetaStoreProgess
			if [[ $? -eq 0 ]]; then
				echo "正在启动 HIVE MetaStore..."
				`nohup hive --service metastore > ${HIVE_LOG_HOME}/metastore_log 2>&1 &`
			else
				echo "HIVE MetaStore 已经启动"
			fi

			checkHiveServer2Progess
			if [[ $? -eq 0 ]]; then
				echo "正在启动 HIVE HiveServer2..."
				`nohup hive --service hiveserver2 > ${HIVE_LOG_HOME}/hiveserver2_log 2>&1 &`
			else
				echo "HIVE HiveServer2 已经启动"
			fi
		fi
}

case ${1} in
	start )
		startProgess
		;;
	stop )
		stopProgess
		;;
	status )
		checkHiveMetaStoreProgess
		if [[ $? -eq 0 ]]; then
			echo "HIVE MetaStore 未启动"
		else
			echo "HIVE MetaStore 已经启动"
		fi

		checkHiveServer2Progess
		if [[ $? -eq 0 ]]; then
			echo "HIVE HiveServer2 未启动"
		else
			echo "HIVE HiveServer2 已经启动"
		fi
		;;
	* )
		echo "参数异常 hive-service.sh start|stop|status"
		;;
esac
相关推荐
小何好运暴富开心幸福2 天前
C++之日期类的实现
开发语言·c++·git·bash
Maple_land2 天前
Linux进程第五讲:PPID与bash的关联、fork系统调用的原理与实践操作(上)
linux·运维·服务器·centos·bash
工作中的程序员2 天前
hive sql优化基础
hive·sql
风跟我说过她3 天前
Sqoop的安装与配置
hive·hadoop·经验分享·centos·hbase·sqoop
___波子 Pro Max.3 天前
Shell脚本变量${}与命令$()替换区别
bash
九天轩辕5 天前
用一个 Bash CLI 管理多款 AI 开发工具:jt-code-cli 实战与原理解析
开发语言·人工智能·bash
许商7 天前
【stm32】bash自动配置buildenv
开发语言·bash
zhaotiannuo_19987 天前
linux centos 7 解决终端提示符出现-bash-4.2的问题
linux·centos·bash
DashingGuy7 天前
hive、spark任务报错或者异常怎么排查以及定位哪段sql
hive·sql·spark
vortex57 天前
Bash 中的 shopt -s globstar:递归 Glob 模式详解
开发语言·chrome·bash