shell脚本实现实时检测文件变更
使用python做web开发,现在流行使用uwsgi调用python程序,但是使用uwsgi一段时间发现有一个弊端,就是每次更改源代码后必须重启uwsgi才能生效,包括更改模板文件也是,我是个懒人,再经过一段时间反复的更改-重启后我终于忍受不了,决定写一个脚本来定时程序目录的文件改动,并及时自动重启uwsgi,来解放我的双手可以不用理会这些琐碎的重启工作. 用了点时间来编写了一个脚本用来判断是否更改,然后判断是否需要重启uwsgi.
下面放出脚本内容:
#!/bin/bash
# Author : cold
# Filename : checkchange.sh
# Useage : sh checkchange.sh [dir]
checkisdir()
# Have one argument
# The argument is a directory
for i in `ls $1 | sed -e 's/ /\n/g'`
do
if [ -d $1/$i ]
then
if [ $i == "bin" -o $i == "lib" -o $i == "include" ] # 不想检测的目录(这里是使用virtualenv生成的环境文件)
then
continue
fi
dir="$1/$i"
checkisdir $dir
else
files=$files'\n'$1'/'$i
fi
done
echo -e $files
}
while true
do
if [ -e /tmp/stat.tmp ]
then
for i in `checkisdir $1`
do
if [ -e /tmp/patch.tmp ]
then
stat $i | grep Change > /tmp/nstat.tmp
rm -f /tmp/patch.tmp
continue
fi
stat $i | grep Change >> /tmp/nstat.tmp
done
diff /tmp/stat.tmp /tmp/nstat.tmp > /tmp/patch.tmp
if [ $? -eq 0 ]
then
sleep 10
else
/etc/init.d/uwsgi.py restart # 将此处更改为想要做的操作
patch /tmp/stat.tmp /tmp/patch.tmp
fi
else
for i in `checkisdir $1`
do
stat $i | grep Change >> /tmp/stat.tmp
done
continue
fi
done
这里主要测试变更后重启uwsgi,使用方法:我的bottle程序在/code/python下:
复制代码 代码如下:
sh checkchange.sh /code/python &
如果使用svn可以参考下面代码:
#!/bin/bash
# Author : cold
# Filename : checkupdate.sh
# Describle : To Check update of svn
while true
do
cd /code/python
svn up | grep At > /dev/null 2>&1
if [ $? -eq 0 ]
then
sleep 30
fi
svn up | grep Updated > /dev/null 2>&1
if [ $? -eq 0 ]
then
/etc/init.d/uwsgi.py restart
fi
done
栏 目:其它服务器
下一篇:Shell中创建序列和数组(list、array)的方法
本文标题:shell脚本实现实时检测文件变更
本文地址:https://zz.feitang.co/server/34959.html
您可能感兴趣的文章
- 01-06nginx从安装到配置详细说明(安装,安全配置,防盗链,动静分离,配置 HTTPS,性能优化)
- 01-06Nginx性能优化之Gzip压缩设置详解(最大程度提高页面打开速度)
- 01-06Linux系统 Centos7.4手动在线升级到Centos7.7
- 01-06详解nginx安装过程并代理下载服务器文件
- 01-06shell脚本根据进程查找指定容器的方法
- 01-06微服务架构拆分策略详解
- 01-06使用 Apache Dubbo 实现远程通信(微服务架构)
- 01-06微服务架构之服务注册与发现功能详解
- 01-06使用Zabbix 5.4.3监控IPMI的方法
- 01-06微服务架构之服务注册与发现实践示例详解






