ElasticSerach编写Shell启动脚本

1、所有文章优先发表在个人博客上: https://www.xdx97.com
2、后续如果有修改的话,可能忘记更新到CSDN了,给你带来不便,抱歉。
3、个人博客本篇文章地址 : https://www.xdx97.com/article?bamId=644536524079104000

文章转自:https://blog.csdn.net/Yhappy727/article/details/88576847
直接复制下面代码,需要改下你的ES端口,和启动位置。(第十行,和第十八行)
因为启动位置写好了,所以你随便把这个脚本放在那里都可以

#!/bin/bash

# kconfig: 2345 91 11

# description: elasticsearch

#定义变量

PORT=9200

NAME=elasticsearch

ID=`ps -aux | grep "$NAME" | grep -v "grep" | awk '{print $2}'`

CHECK_PORT=`netstat -tnlp|grep "$PORT"`

ELASTICSEARCH_SERVER=/usr/local/elasticsearch-7.4.2/bin/elasticsearch

RETAVL=0

#检查shelk公共函数库是否存在,存在就加载
FUNCTIONS_PATH=/etc/init.d/functions
[ -f $FUNCTIONS_PATH ]&& source $FUNCTIONS_PATH

#检查文件是否存在并可执行
[ -x $ELASTICSEARCH_SERVER ]|| exit 0


#定义函数
#检查是否执行成功
check(){
	RETAVL=$?
	if 
		[[ "$RETAVL" = 0 ]];then
		action "elasticsearch is $1" /bin/true
	else
		action "elasticsearch is $1" /bin/false	
	fi
}
#启动服务
start(){
	if
		[[ "$CHECK_PORT" != "" ]];then
		echo "elasticsearch already running"
	else
	su - es <<!
	
		$ELASTICSEARCH_SERVER -d

exit

!
		check Started				
	fi
}
#停止服务
stop(){
	if
		[[ "$CHECK_PORT" = "" ]];then
		echo "elasticsearch is not running."
	else
		kill -9 $ID
		check Stopped
	fi
}
#重启服务

restart(){
	stop
	sleep 2
	start
}

 
#判断
case "$1" in
start)
		start
		;;
stop)
		stop
		;;
restart)
		restart
		;;
*)
		echo $"Usage:$0{start|stop|restart|help}"

esac

exit $RETAVL

2.增加脚本可执行权限

chmod +x elasticsearch.sh
发布了302 篇原创文章 · 获赞 127 · 访问量 52万+

猜你喜欢

转载自blog.csdn.net/Tomwildboar/article/details/103163924