最近弄logstash 每次启动和关闭都特别麻烦,就弄了个脚本,感谢范明童鞋的帮忙(我七窍通了六窍)

不晓得写的对不对 反正 效果实现了~~~

 

vim  /cuzn/logstash-2.3.4/logssh

 

#!/bin/bash

#chkconfig:2345 85 15

LOGSTASH_DIR=/cuzn/logstash-2.3.4  #logstash绝对路径

LOGSTASH_CONF=$2                         #logstash 配置文件名

start(){

ps aux | grep -v grep | grep $LOGSTASH_CONF &> /dev/null

if [ "$?" != 0 ];then

echo "logstash is already running"

exit

fi

$LOGSTASH_DIR/bin/logstash -f vconf/$LOGSTASH_CONF &

if [ "$?" == 0  ];then

echo "logstash starting......OK"

else

echo "logstash starting......failed"

fi

}

stop(){

ps aux | grep -v grep | grep $LOGSTASH_CONF: &> /dev/null

#if [ $? -ne 0 ];then

# echo "logstash is already stop"

# exit

#fi

#kill -9 logstash

kill -9 $(ps -ef|grep $LOGSTASH_CONF|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ')

if [ "$?" == 0  ];then

echo "logstash stop......OK"

else

echo "logstash stop......failed"

fi

}

status(){

ps aux | grep -v grep | grep logstash: &> /dev/null

if [ "$?" == 0  ];then

echo "logstash is running"

else

echo "logstash is stopped"

fi

}

case $1 in 

start)

start;;

stop)

stop;;

restart)

stop

start;;

status)

status;;

*)

echo "USAG:(start|stop|restart|status)";;

esac




启动方式  
logssh start xx.conf
logssh stop xx.conf

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权