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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章