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

 

转载于:https://www.cnblogs.com/dengcongcong/p/10992294.html

你可能感兴趣的:(ELK的启动脚本)