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

时间:2017-09-12 01:32:14

标签: recursion path systemd subdirectory

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

mysolution.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

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

mysolution.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

甚至可以这样做吗?我真的不想手动维护每个必须监控的目录和文件。我真的只需要在/ var / opt / mysolution / *目录的任何子目录中收到新文件的通知。 systemd可以做到这一点,而不必变成某种黑客?

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

0 个答案:

没有答案
相关问题