Skip to main content

How often is a service triggered by a DirectoryNotEmpty in a systemd.path unit? [Resolved]

if I have a A.path monitors queue folder with a DirectoryNotEmpty directive, and A.service process and remove files from queue. If I start the path unit with queue containing 10 files, will A.path triggers the service until the folder gets empty? If so, how often does it try to trigger the service? (What about if the service does not change the content of queue?)

Thank you

Question Credit: Abitbol
Question Reference
Asked July 18, 2019
Tags: systemd
Posted Under: Unix Linux
1 Answers

A Systemd path unit with a DirectoryNotEmpty directive only triggers the corresponding service when something changes in the directory. Systemd internally uses the inotify API to monitor changes to the directory. Systemd does not use a timer to periodically start the service, no matter if the directory is empty or not. This means that the service is not triggered again until the directory is empty. Instead, the service has to handle all the files in the directory, typically by processing the files and removing or moving them to some other directory. For example, if the service handles just one file, and nothing happens in the directory after that, then the service is never called again.

"DirectoryWentFromEmptyToNonEmpty" would perhaps be a more appropriate name for the DirectoryNotEmpty directive, although my tests show that the service is triggered each time a file is added to the directory. (This in turn complicates things a bit, because, if the file consuming process takes a long time, you may have several processes running in parallel, which need to be coordinated.)

credit: Johan Myréen
Answered July 18, 2019
Your Answer