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

你可能感兴趣的:(大数据学习)