跳转到主要内容

运行响应inotify事件的脚本

项目描述

inotify_service可用于构建类似过时的incron的Linux服务。

它基于(简单且高效的)python asyncinotify包。

我们在生产中使用它,负载很低。我们无法提供关于性能的反馈。

安装

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: "sleep 2 | echo {path} > /tmp/titi.log"
  directory: "/tmp"
  pattern: "[a-z0-9_]+\\.pdf$"
  events:
    - "CLOSE_WRITE"
    - "MOVED_TO"

- script: "echo {path}"
  directory: "/home/gas/tmp/"
  events:
    - "CLOSE_WRITE"

必填参数

script : 要启动的命令,以下参数将被传递

  • path : 磁盘上的绝对路径

  • filename: 文件名

  • name : 事件名称(CLOSE_WRITE …)

directory : 要监视的目录

events : 应触发脚本的事件的列表

可选参数

pattern : 用于匹配可管理的文件名的正则表达式模式

Systemd服务设置

如果您使用了上面相同的目录,您可以直接使用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 查看哈希值)

上传时间 Python 3

由以下支持

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页面