From 10ddd2d1c5691a278733c804ddf8addaacdd38d3 Mon Sep 17 00:00:00 2001 From: lizw <1183409807@qq.com> Date: Fri, 1 Jul 2022 14:34:45 +0800 Subject: [PATCH] 04elasticsearch.sh --- 00base/04elasticsearch.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 00base/05kibana.sh | 0 2 files changed, 62 insertions(+) create mode 100644 00base/04elasticsearch.sh create mode 100644 00base/05kibana.sh diff --git a/00base/04elasticsearch.sh b/00base/04elasticsearch.sh new file mode 100644 index 0000000..6f60804 --- /dev/null +++ b/00base/04elasticsearch.sh @@ -0,0 +1,62 @@ +#!/bin/bash +#set -x +set -e + +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + +installPath=/opt/elasticsearch/elasticsearch-7.17.5 +serverName=test_elasticsearch +cmd=$1 + +startServer() { + pid=$1 + if [ -z $pid ];then + echo -e "$echoPrefix nohup $installPath/bin/elasticsearch >>/dev/null 2>&1 & $echoSuffix" + nohup $installPath/bin/elasticsearch >>/dev/null 2>&1 & + echo "$serverName 启动成功!" + else + echo "$serverName 正在运行..." + fi + echo "日志目录: cd $installPath/logs" +} + +stopServer() { + pid=$1 + if [ -z $pid ];then + echo "$serverName 未运行" + else + echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix" + ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill + echo "$serverName 已停止!" + fi +} + +restartServer() { + pid=$1 + if [ ! -z $pid ];then + stopServer $pid + sleep 3s + fi + startServer +} + +pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` +# 操作参数: restart start stop kill +if [ "$cmd" == "restart" ];then + restartServer $pid +elif [ "$cmd" == "start" ];then + startServer $pid +elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then + stopServer $pid +else + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: restart start stop kill" + echo "日志目录: cd $installPath/logs" + else + echo "输入操作参数: restart start stop kill" + echo "pid=$pid | $serverName 正在运行... | 日志目录: cd $installPath/logs" + fi +fi + +# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/04elasticsearch.sh) [cmd] diff --git a/00base/05kibana.sh b/00base/05kibana.sh new file mode 100644 index 0000000..e69de29