使用 systemd 路径单元监视树并将参数传递给服务

Vec*_*tor 9 recursion path subdirectory systemd

使用 systemd 路径单元,是否可以监视,而不仅仅是单个目录或文件,而是递归地监视目录中的所有子目录,而无需显式列出每个子目录?我尝试了通配符,但即使文档提到了通配符扩展,它们也不起作用。我发现 .path 单位的价值极其有限。

我的解决方案路径

[Unit]
Description="File monitor path unit"

[Path]
DirectoryNotEmpty=/var/opt/mysolution
#DirectoryNotEmpty=/var/opt/mysolution/*
#PathChanged=/var/opt/mysolution/*/*
#PathChanged=/var/opt/mysolution/subdir

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

注释掉的行是根本不起作用的行

我的解决方案.service

[Unit]
Description="File monitor service unit"

[Service]
Type=oneshot
ExecStart=/bin/chmod -fR ug+rw /var/opt/mysolution/subdir
#ExecStart=/bin/chmod -fR ug+rw /var/opt/mysolution/*
# I don't want to change permissions on mysolution, just all files and dirs under that directory

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

有可能做到这一点吗?我真的不想手动维护必须监视的每个单独的目录和文件。我实际上只需要通知 /var/opt/mysolution/* 目录的任何子目录中的新文件。systemd 可以做到这一点而不必变成某种黑客吗?

此外,一旦出现新文件,最好将其传递给相应的服务。有没有办法做到这一点?