> need to process to file added to a directory, then remove them. Files can be large (20KiB to 5 GiB) and arrive slowly (via scp or ftp). How can I monitor a path (possibly with a systemd.path unit) and only react when the new file has finished writing?
And as the question details DirectoryNotEmpty is not adequate because zero byte files still being written will trigger it and there's nothing after.
Indeed all the path unit conditions: PathExists=, PathExistsGlob=, PathChanged=, PathModified=, DirectoryNotEmpty= suffers from this.
One could do the an old fashioned while inotifywait -r -e close_write "/foo/bar/" but now you need to think about the script dying and restarting it which of course leads back to systemd (see https://ma.ttias.be/auto-restart-crashed-service-systemd/ for more) and then one asks: why can't systemd do this alone?
I'm a little confused as to why PathChanged didn't work for you.
From the man page
> PathChanged= may be used to watch a file or directory and activate the configured unit whenever it changes. It is not activated on every write to the watched file but it is activated if the file which was open for writing gets closed. PathModified= is similar, but additionally it is activated also on simple writes to the watched file.
Actually this is a common pattern in enterprise IT where you need to integrate heterogeneous apps (i.e. at least one of the app is "legacy").
E.g. at my job the main system (the one "selling" stuff to customer and managing inventory of this "stuff") routinely sends production data to the datawarehouse, the accounting system, sends invoices and confirmations to a document management systems for formatting and sending (via email).
And considering both how old it is, and the fact that the data can be large-ish... most of this is sent out as files.
This also mean that the various consumers need some sort of trigger to start processing the data.
Yeah reacting to files for integrating systems is definitely done, even if it is a poor idea. I don't think systemd is a good system to do it though because I doubt it could ever handle errors or retries in an appropriate manner for the system.
In some cases you’ll find that systemd can be the core of your architecture and free you from writing a lot of software and reduce overall complexity.
Let systemd do the work, that’s my motto.