git

git同步自动拉取操作

2019-02-21  本文已影响0人  空气KQ

安装yum -y install inotify-tools

例子监听文件创建和更新事件

inotifywait -r -m -e create,modify  --timefmt '%Y%-m-%d %H:%M:%S' --format '%T %w%f' --exclude='/root/demo/src/.env'  /root/demo/src/

shell 脚本git.sh

#path=/root/demo/git/
/usr/bin/inotifywait -mrq --format '%w%f' -e create,modify,delete ${path} | while read line
do
        cd /www/wwwroot/hunli/
        /usr/bin/git pull origin master &>/dev/null && /usr/bin/php artisan migrate > /dev/null
done

[root@250 nginx]# inotifywait -h
inotifywait 3.14
Usage: inotifywait [ 选项 ] file1 [ file2 ] [ file3 ] [ ... ]
选项:
    @<file>       排除某些文件.
    --exclude <pattern>  排除匹配的文件
    --excludei <pattern> 大小写不敏感排除指定样式的文件
    -m|--monitor  保持监听状态,如果不设置这个选项,inotifywait只执行一次就会退出。
    -d|--daemon   类似于-m,但是在后台运行,输出事件到特定的文件可以通过 --outfile. 意味着 --syslog.
    -r|--recursive  递归监听目录
    -s|--syslog     发送错误日志到syslog而不是stderr
    -q|--quiet      静态模式,不输出信息
    -qq             什么都不输出
    --timefmt <fmt>  时间格式
    -e|--event <event1> [ -e|--event <event2> ... ]
        监听指定的事件,如果不指定,所有的事件都被监听。
Exit status:
    0  -  收到了指定的事件
    1  -  收到了没有指定的事件,或者出现了一些错误
    2  -  没有收到事件

可以监听的事件:
  access    访问,读取文件。
  modify    修改,文件内容被修改。
  attrib    属性,文件元数据被修改。
  move  移动,对文件进行移动操作。
  create    创建,生成新文件
  open  打开,对文件进行打开操作。
  close 关闭,对文件进行关闭操作。
  delete    删除,文件被删除。

重启动nginx

#!/bin/bash
inotifywait -m -e close_write -r /usr/local/openresty/nginx/conf/ |
while read events;
do
    echo $events;
    nginx -s reload;
    echo "Nginx reloaded!"
done

开启启动脚本

vim /etc/rc.local
sh /root/sh/hb.sh& >/root/sh/hb.log 2>$1
上一篇 下一篇

猜你喜欢

热点阅读