运行响应 inotify 事件的脚本
项目描述
inotify_service 可用于构建类似于过时的 incron 的 Linux 服务。
它基于(简单而高效的)python asyncinotify 包。
我们(Majerti)在低负载的生产中使用它。我们没有任何关于性能的反馈要提供。
安装
apt-get install python3-venv
python3 -m venv /usr/local/inotify_service_venv
source /usr/local/inotify_service_venv/bin/activate
pip install inotify_service
设置
您可以在 github 页面上下载合适的 log.conf 示例文件:
https://github.com/majerteam/inotify_service/
mkdir -p /etc/inotify_service/conf.d
cp log.conf /etc/inotify_service/
为要监视的目录添加 yaml 配置文件。
每个 yaml 文件可以包含一个或多个配置到 yaml 列表中
- script: <s>"sleep</s> <s>2</s> <s>|</s> <s>echo</s> <s>{path}</s> <s>></s> <s>/tmp/titi.log"</s>
directory: <s>"/tmp"</s>
pattern: <s>"[a-z0-9_]+\\.pdf$"</s>
events:
- <s>"CLOSE_WRITE"</s>
- <s>"MOVED_TO"</s>
- script: <s>"echo</s> <s>{path}"</s>
directory: <s>"/home/gas/tmp/"</s>
events:
- <s>"CLOSE_WRITE"</s>
强制参数:
script:要启动的命令,传递以下参数
path :磁盘上的绝对路径
文件名:文件的名称
name : 事件名称 (CLOSE_WRITE …)
directory:要监视的目录
events:应该触发脚本的事件列表
可选参数:
pattern:用于匹配可以管理的文件名的正则表达式模式
系统服务设置
如果您使用与上面相同的目录,您可以只使用可以在 github 存储库中下载的 .service 文件。
https://github.com/majerteam/inotify_service/
cp inotify_service.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable inotify_service.service
systemctl start inotify_service.service
systemctl status inotify_service.service # Default configuration should print the directories that are watched
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
inotify_service-1.0.2.tar.gz
(17.4 kB
查看哈希)
内置分布
inotify_service-1.0.2-py3-none-any.whl
(19.0 kB
查看哈希)