
service unit to activate, in case you want to give it a different name to that of your. DirectoryNotEmpty= does what it says on the box, that is, it activates the associated unit if the monitored directory contains files or subdirectories.PathModified=, on the other hand, does activate the unit when anything is changed in the file you are monitoring, even before you close the file.The associated unit is executed when the file is closed. It is not activated on every write to the watched file but only when a monitored file open for for writing is changed and then closed. PathChanged= watches a file or directory and activates the configured unit whenever it changes.This lets you check, for example, whether a file with a certain extension exists. PathExistsGlob= works in a similar fashion, but lets you use globbing, like when you use ls *.jpg to search for all the JPEG images in a directory. If it does, the associated unit gets triggered. PathExists= monitors whether the file or directory exists.First, you have the what-to-watch-for directives: Path units contain a new section,, with few more directives. For example, if you have a picchanged.path unit to monitor the snapshot from your webcam, you will also have a rvice that will execute a script when the snapshot is overwritten. service unit with the same name) when something happens to the monitored file or directory. path, and it monitors a file or directory. Anatomy of a Path UnitĪ systemd path unit takes the extension. And, overwriting an image is exactly the kind of event we are talking about here.

Path units allow you to trigger a service when an event happens in the filesystem, say, when a file gets deleted or a directory accessed.

Because, you see, systemd offers yet another type of units, paths, that can help you out. In fact, it even overwrote the last picture it took when it detected movement so as not to fill the storage of the device.ĭoes that mean the system is useless? Not by a long shot. Last time we saw how the surveillance system took pictures, but it did nothing with them. For the practical example, you’ll see how you can use one of these units to extend the surveillance system we talked about last time.
File monitor linux how to#
This installment does something different yet again and covers how to create a unit that starts a service when something changes in the filesystem. So far in this systemd multi-part tutorial, we’ve covered how to start and stop a service by hand, how to start a service when booting your OS and have it stop on power down, and how to boot a service when a certain device is detected.
