2

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

0

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

  • Thank you. Would a PathModified be more appropriate then to retrigger a service that only move one file from the queue? – Abitbol Jul 16 at 16:25
  • PathModified is intended to point to a file, not a directory. You would need to know the file names in advance, or use PathExistsGlob. But why can't you process all the files in sequence in the service process if there are more than one file in the directory? This seems more robust to me. For example, if you use PathExistsGlob, and there is more than one matching file in the directory when the path unit is started, the service process will only be triggered once. – Johan Myréen Jul 16 at 17:40
  • Okay, so this would give me the same result as using DirectoryNotEmpty then... If the path is stopped while the directory is not empty, and then restart, will it retrigger the service? I need to manage several queues with inter-dependencies, at first it seemed to me that I could manage all of them in an "event" way using only systemd, I don't think it's possible now. – Abitbol Jul 17 at 8:36
  • Thanks you, I created a new post with more details about what I am trying to do: unix.stackexchange.com/questions/530613/… – Abitbol Jul 17 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.