GNU Direvent |
|
Directory event monitoring daemon |
Sergey Poznyakoff |
3 Quick Start
Let’s suppose you have a directory where users can upload their files and you want these files to be processed right after upload, in real time. Let this directory be /home/ftp/incoming and the program to process the upload be /usr/bin/upload. Let’s also suppose that this program expects name of the uploaded file as its argument.
To make direvent
handle this task, you would need to create a
watcher for the upload directory which would handle the ‘create’ event:
watcher {
path /home/ftp/incoming;
event create;
# more statements follow...
On this event, the watcher is to invoke /usr/bin/upload
with the name of the created file as an argument. To make it
possible, the direvent
configuration file provides macro
variables, which can be used in the command
argument at
configuration time and which are expanded to the actual values before
the command is executed. Macro variables are referred to using the
same syntax as shell variables: a dollar sign followed by the variable
name, optionally enclosed in curly braces. The ‘file’ variable
is expanded to the name of the file for which the event is reported.
This name is relative to the current working directory which, by the
time the handler is executed, is set to the directory where the event
occurred. Thus, the handler can be configured as:
command "/usr/bin/upload $file";
To summarize, the watcher declaration is:
watcher { path /home/ftp/incoming; event create; command "/usr/bin/upload $file"; }
Before invoking the handler, the following operations are performed:
- The current working directory is set to the directory where the event occurred.
- If the
environ
statement is present in the watcher, the environment is modified according to its rules. (see environment modification) - The standard input is closed.
- If the ‘stdout’ option is supplied, the standard output is captured and redirected to the syslog. Otherwise it is closed.
- If the ‘stderr’ option is supplied, the standard error is captured and redirected to the syslog. Otherwise it is closed.
- File descriptors above 2 are closed.
- Macro variables are expanded. See macro expansion.
- If the ‘shell’ option is set, the handler is invoked via the
shell, as
/bin/sh -c "command"
.Otherwise, word splitting is performed on the resulting command line. The first word is treated as the pathname of the program, which is then invoked via the
execve
system call.
This document was generated on July 13, 2019 using makeinfo.
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.