| 用途 | 文件系统事件驱动的服务触发 |
|---|---|
| 指令 | PathExists / PathChanged / PathModified |
| 激活 | path 与同名 service 配对) |
完整示例
完整示例
# /etc/systemd/system/spool-watch.path
[Unit]
Description=watch incoming files
[Path]
DirectoryNotEmpty=/var/spool/incoming
[Install]
WantedBy=paths.target
# /etc/systemd/system/spool-watch.service
[Unit]
Description=process incoming
[Service]
Type=oneshot
ExecStart=/opt/scripts/process-incoming.sh
sudo systemctl daemon-reload && sudo systemctl enable --now spool-watch.path
systemctl list-units --type=path --no-pagerinotify 有实例数上限(fs.inotify.max_user_watches):监控大目录树前评估,或退化为 timer 周期扫。