Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

24.4.7. Monitoring Files and Directories with gamin

Starting with Red Hat Enterprise Linux 6.8, the GLib system library uses gamin for monitoring of files and directories, and detection of their modifications on NFS file systems. By default, gamin uses polling for NFS file systems instead of inotify. Changes on other file systems are monitored by the inotify monitor that is implemented in GLib directly.
As a subset of the File Alteration Monitor (FAM) system, gamin re-implements the FAM specification with the inotify Linux kernel subsystem. It is a GNOME project, but without any GNOME dependencies. Both glib2 and gamin packages are installed by default.
By default, gamin works without the need of any configuration and it reverts to using polling for all paths matching /mnt/* or /media/* on Linux. Users can override or extend these settings by modifying the content of one of the following configuration files:
  • /etc/gamin/gaminrc
  • $HOME/.gaminrc
  • /etc/gamin/mandatory_gaminrc
The configuration file accepts only the following commands:

Commands accepted by the configuration file

notify
To express that kernel monitoring should be used for matching paths.
poll
To express that polling should be used for matching paths.
fsset
To control what notification method is used on a filesystem type.
An example of such configuration file can be seen here:
# configuration for gamin
# Can be used to override the default behaviour.
# notify filepath(s) : indicate to use kernel notification
# poll filepath(s)   : indicate to use polling instead
# fsset fsname method poll_limit : indicate what method of notification for the file system
#                                  kernel - use the kernel for notification
#                                  poll - use polling for notification
#                                  none - don't use any notification
#                                  the poll_limit is the number of seconds
#                                  that must pass before a resource is polled again.
#                                  It is optional, and if it is not present the previous
#                                  value will be used or the default.
notify /mnt/local* /mnt/pictures* # use kernel notification on these paths
poll /temp/*                      # use poll notification on these paths
fsset nfs poll 10                 # use polling on nfs mounts and poll once every 10 seconds
The three configuration files are loaded in this order:
  1. /etc/gamin/gaminrc
  2. ~/.gaminrc
  3. /etc/gamin/mandatory_gaminrc
The /etc/gamin/mandatory_gaminrc configuration file allows the system administrator to override any potentially dangerous preferences set by the user. When checking a path to guess whether polling or kernel notification should be used, gamin checks first the user-provided rules in their declaration order within the configuration file and then check the predefined rules. This way the first declaration for /mnt/local* in the example override the default one for /mnt/*.
If gamin is not configured to use the poll notifications on a particular path, it decides based on the file system the path is located on.