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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值