flume 启动,停止,重启脚本
#!/bin/bash#echo "begin start flume..."#flume的安装根目录(根据自己情况,修改为自己的安装目录)path=/sysware/apache-flume-1.8.0-binecho "flume home is :$path"#flume的进程名称,固定值(不用修改)JAR="flume"#flume的配置文件名称(根据自己的情况,修改为自己的flume配置文件名称)Flumeconf="flume-conf.conf"#定义的soure名称agentname="agent1"function start(){echo "begin start flume process ...."#查找flume运行的进程数num=`ps -ef|grep java|grep $JAR|wc -l` #判断是否有flume进程运行,如果有则运行执行nohup命令if [ "$num" = "0" ] ;thennohup $path/bin/flume-ng agent --conf conf -f $path/conf/$Flumeconf --name $agentname -Dflume.root.logger=INFO,console &echo "start success...."echo "日志路径: $path/logs/flume.log"elseecho "进程已经存在,启动失败,请检查....."exit 0fi}function stop(){echo "begin stop flume process.."num=`ps -ef|grep java|grep $JAR|wc -l`#echo "$num...."if [ "$num" != "0" ];then#正常停止flumeps -ef|grep java|grep $JAR|awk '{print $2;}'|xargs killecho "进程已经关闭..."elseecho "服务未启动,无须停止..."fi}function restart(){#echo "begin stop flume process .."#执行stop函数stop#判断程序是否彻底停止num='ps -ef|grep java|grep $JAR|wc -l'#stop完成之后,查找flume的进程数,判断进程数是否为0,如果不为0,则休眠5秒,再次查看,直到进程数为0while [ $num -gt 0 ];dosleep 5num='ps -ef|grep java|grep $JAR|wc -l'doneecho "flume process stoped,and starting..."#执行startstartecho "started...."}#case 命令获取输入的参数,如果参数为start,执行start函数,如果参数为stop执行stop函数,如果参数为restart,执行restart函数case "$1" in"start")start;;"stop")stop;;"restart")restart;;*);;esac 以上脚本命名成.sh文件,例如我命名为 flume.sh ,存放路径为 /sysware
调用start 函数:
sh /sysware/flume.sh start
调用 stop命令
sh /sysware/flume.sh stop
调用重启命名
sh /sysware/flume.sh restart
以上脚本即可完成flume的start,stop,restart,并且在后台运行的需求。
此博客中涉及到一些flume,shell命令知识点
shell :函数、if 、while ,case、wc,管道符| 、sleep 等,可参考linux分类进行学习
flume:flume启动命令 ,可参考大数据分类进行学习
转载请注明:SuperIT » flume 启动,停止,重启脚本
