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
相关推荐
廖圣平1 天前
从零开始,福袋直播间脚本研究【八】《策略模式》
开发语言·python·bash·策略模式
蓝眸少年CY2 天前
Hive - 函数、压缩与优化
数据仓库·hive·hadoop
西西弗Sisyphus2 天前
Linux Shell 脚本中的 Shebang(#! /bin/bash)是什么
linux·bash·shebang
MarkHD3 天前
RPA工程化实践:重构电商抓取项目——从混乱脚本到模块化、可配置化系统
重构·bash·rpa
晨曦蜗牛3 天前
Windows 上 Claude Code 报错 “requires git-bash“ 的完整解决方案
windows·git·bash
淮北4944 天前
bash下好用的快捷键以及linux常用指令
linux·开发语言·ubuntu·bash
zhojiew4 天前
[INFRA] EMR集群中Hive和Spark集成Glue Data Catalog过程的深入分析
hive·hadoop·spark·aws·bigdata
bukeyiwanshui4 天前
Hive的使用
数据仓库·hive·hadoop
添柴少年yyds5 天前
hive锁机制
数据仓库·hive·hadoop
蓝眸少年CY5 天前
Hive - 安装与使用
数据仓库·hive·hadoop