ELK的启动脚本

作者:邓聪聪

方便自己的应用,制作一个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
          /elk/elasticsearch-6.3.0/bin/elasticsearch -d
          action "start elasticsearch:" true
        else
          su - elk -c "/elk/elasticsearch-6.3.0/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
}
stop() {
    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}'`
        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

 

posted @ 2019-06-09 00:17  邓聪聪  阅读(762)  评论(0编辑  收藏  举报