Systemd offers unit files whom control monitoring of a certain path trough inotify: systemd.path(5). If a file or directory is modified in the watched path the corresponding systemd.service(5) is called.
According to the inotify(7) man page:
To determine what events have occurred, an application read(2)s from the inotify file descriptor. If no events have so far occurred, then, assuming a blocking file descriptor, read(2) will block until at least one event occurs (unless interrupted by a signal, in which case the call fails with the error EINTR; see signal(7)).
Each successful read(2) returns a buffer containing one or more of the following structures:
struct inotify_event { int wd; /* Watch descriptor */ uint32_t mask; /* Mask of events */ uint32_t cookie; /* Unique cookie associating related events (for rename(2)) */ uint32_t len; /* Size of name field */ char name[]; /* Optional null-terminated name */ };
So if systemd see a change in the watched path, is there a way of getting any data from the read(2) command? Notably I need the name[] to be used as an argument to the command for the ExecStart= in the systemd.service(5) unit statement.
[Service]
ExecStart=/usr/bin/command --file=$inotifyName