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.

ExecStart=/usr/bin/command --file=$inotifyName
  • 1
    I know read(2) is a system call. I do not want to do anything with read(2). I want to run a command from a systemd.service file, triggered by a systemd.path file, which in turn uses inotify and I assume it uses something like read(2). I need the a string containing the filename that triggered the event appended to the ExecStart statement in the unit file.
    – Tim
    Jan 25, 2014 at 19:09
  • 2
    Did you find out? I'm looking at running a script as well. Jan 17, 2016 at 5:45
  • 1
    Hi, no never found (I stopped looking to be honest)
    – Tim
    Jun 28, 2018 at 9:30
  • 1
    systemd doesn't pass its file descriptor that has inotify open to the called process. The python inotify should be easy enough to script up.
    – danblack
    Aug 24, 2018 at 6:27
  • 2
    It's a fair question, and I'd like to hear the same. In particular, because I finally got the skeleton of my monitoring service moved over from inotify (!) with hope hung on using systemd Path units like inotify! :( I feel I (we) must be overlooking something...? Dec 21, 2018 at 19:21

1 Answer 1


Steward gave a quiet complete proposal for a reasonable workaround on unix.stackexchange.com

After some playing I found the easiest way was to use one *.path file per path and template each path into a single *@.service file.


  • 1
    Welcome to Super User! Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
    – DavidPostill
    Aug 19, 2020 at 17:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .