项目需求:
文档修改后,杀掉mq进程,mq重启
一、检查是否有安装inotify 如果没有就安装 ,
rpm -qa inotify-tools
没有先安装epol源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
二、安装
yum install inotify-tools -y
三、使用:
找到启动命令的位置
which inotifywait
编写脚本:
vim mqrestart.sh
#!/bin/bash
#chkconfig:345 88 14
file1=/home/work/webserver/document/tsqianjia/apps/web/backend/mqDeptOrUserReceive.php
file2=/home/work/webserver/document/tsqianjia/common/Service/ResourceReceive.php
/usr/bin/inotifywait -m -r $file1 $file2 | while read LINE
do
if [[ $LINE = *MODIFY* ]];then
PID=$(ps -ef | grep "mqDeptOrUserReceive" | grep -v "grep" | awk '{print $2}')
for ID in $PID
do
kill -9 $ID
done
fi
done
nohup ./mqrestart.sh >/var/log/inotify/mqrestart.log 2>&1 &