ELK 一键启动脚本,总想着怎么偷懒

假的都是假的--------------------------------东拼西凑的脚本还挺好使 ^^

#!/bin/sh
PATH=$PATH
. /etc/init.d/functions

start() {
    if [ `ps aux|grep elasticsearch | grep -v grep|wc -l` -eq 0 ];then
        if [ `whoami` == elk ];then
          /usr/elk/elasticsearch/bin/elasticsearch -d
          action "start elasticsearch:" true
        else
          su - elk -c "/usr/elk/elasticsearch/bin/elasticsearch -d"
          if [ $? -eq 0 ];then
             touch /var/lock/subsys/elasticsearch
             action "start elasticsearch:" true
          else
             action "start elasticsearch:" false
          fi
        fi
    else
        echo "elasticsearch is running"
    fi
	
	nohup /usr/elk/logstash/bin/logstash -f /usr/elk/logstash/default.conf > /usr/elk/elkrunlog/logstash/logstash.log 2>&1 &
	action "start logstash:" true
	nohup /usr/elk/kibana/bin/kibana > /usr/elk/elkrunlog/kibana/kibana.log 2>&1 &
	action "start kibana:" true
}
stop() {
     if [ `ps aux|grep kibana | grep -v grep|wc -l` -eq 0 ];then 
        echo "No running program found kibana"
    else
        ps_uid=`ps aux|grep kibana | grep -v grep | awk '{print $2}'`
        kill -9 $ps_uid
        #[ $? -eq 0 ] && rm -f /var/lock/subsys/kibana
        action "kibana is stop" true
    fi
	
	if [ `ps aux|grep logstash | grep -v grep|wc -l` -eq 0 ];then 
        echo "No running program found logstash"
    else
        ps_uid=`ps aux|grep logstash | grep -v grep | awk '{print $2}'`
        kill -9 $ps_uid
        #[ $? -eq 0 ] && rm -f /var/lock/subsys/logstash
        action "logstash is stop" true
    fi
	
    if [ `ps aux|grep elasticsearch | grep -v grep|wc -l` -eq 0 ];then 
        echo "No running program found elasticsearch"
    else
        ps_uid=`ps aux|grep elasticsearch | grep -v grep | awk '{print $2}'`
        su - elk -c "kill -9 $ps_uid"
        [ $? -eq 0 ] && rm -f /var/lock/subsys/elasticsearch
        action "elasticsearch is stop" true
    fi
}
restart() {
    stop
    start
}
case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    stop
    start
    ;;
*)
    echo $"Use $0 start|stop|restart"
esac
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值