Skip to main content

filesystem watcher

fs-watcher on PyPI fs-watcher on PyPI GitHub issues for Watcher

Overview

Watcher is a daemon that watches specified files/folders for changes and fires commands in response to those changes. It is similar to incron, however, configuration uses a simpler to read ini file instead of a plain text file. Unlike incron it can also recursively monitor directories.

It’s written in Python, making it easier to hack.

This fork is a rewritting of the code using python-daemon implementation of PEP3143 with additional features:

  • async commands executing which allows several copies of command can be executed simultaneously for single job

  • capturing command output to separate log file

  • exclude watching files by regular expression

  • perform actions on successful/failure command completion.

Requirements

Watcher supports both Python 2.7 and Python 3.x. It has following dependencies which can be installed with your package manager or pip:

To install dependencies on Debian:

sudo apt-get install python-pyinotify python-daemon python-lockfile python-chardet python-future
sudo apt-get install python3-pyinotify python3-daemon python3-lockfile python3-chardet python3-future

To install dependencies on Gentoo:

emerge -av dev-python/pyinotify dev-python/python-daemon dev-python/lockfile dev-python/chardet dev-python/future

pip will install dependencies automatically.

Installation

Debian

Download latest deb package from GitHub releases page and install it with dpkg.

sudo dpkg -i fs-watcher_X.Y.Z-0_all.deb

In addition to Watcher itself, it will install:

  • sample configuration file to /etc/watcher.ini

  • systemd service fs-watcher (in disabled state).

To start using Watcher you must change /etc/watcher.ini to suit your needs and enable/start fs-watcher service.

Pip

System-wide using pip:

sudo pip install fs-watcher
sudo pip3 install fs-watcher

This command will install:

  • Python modules for Watcher

  • sample configuration file

  • samples of startup scripts

  • executable to start Watcher

Use following command to check exact locations:

pip show -f fs-watcher

There are samples of startup scripts. Use your init system manual to install them properly. Check/fix path to Watcher executable in samples before using, by default it is assumed to be /usr/sbin/watcher.

For systemd:

cp share/init/fs-watcher.service /etc/systemd/system/fs-watcher.service
systemctl daemon-reload
systemctl enable fs-watcher
systemctl start fs-watcher

For SysV:

cp share/init/fs-watcher.sysvinit /etc/init.d/fs-watcher
update-rc.d fs-watcher defaults
/etc/init.d/fs-watcher start

For OpenRC:

cp share/init/fs-watcher.openrc /etc/init.d/fs-watcher
rc-update add fs-watcher default
/etc/init.d/fs-watcher start

Configuration

Check provided watcher.ini file for an example job configuration. The config file should reside in /etc/watcher.ini or ~/.watcher.ini. You can also specify the path to the config file as a command line parameter using the --config option.

If you edit the ini file you must restart the daemon for it to reload the configuration.

Usage

usage: watcher [-h] [--version] [-c CONFIG] [-v] {start,stop,restart,debug}

positional arguments:
  {start,stop,restart,debug}
                                                What to do.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -c CONFIG, --config CONFIG
                                                Path to the config file (default: None)
  -v, --verbose         verbose output

Debug mode

You can start Watcher with debug positional argument to prevent it from forking to the background and log messages to stdout:

watcher debug

Increasing the amount of inotify watchers

There is a limit of max number of inotify watchers. When this limit is not enough to monitor all jobs, the limit must be increased for Watcher to work properly. You can find following error in log when facing this limit:

add_watch: cannot watch /...... WD=-1, Errno=No space left on device (ENOSPC)

If you are running Debian, RedHat, or another similar Linux distribution, run the following in a terminal to increase this limit:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Increasing the amount of queued events

There is a limit of max queued events. When this limit is not enough to monitor all jobs, the limit must be increased for Watcher to work properly. You can find following warning in log when facing this limit:

pyinotify - WARNING - Event queue overflowed.

If you are running Debian, RedHat, or another similar Linux distribution, run the following in a terminal to increase this limit:

echo fs.inotify.max_queued_events=65536 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Metadata

Release files for fs-watcher 1.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fs-watcher 1.0.11
File Size Uploaded
fs-watcher-1.0.11.tar.gz 16.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fs-watcher 1.0.11
File Interpreter ABI Platform
fs_watcher-1.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 33.4 kB

Release files / fs-watcher-1.0.11.tar.gz

Download URL fs-watcher-1.0.11.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f9a71f43fe6f9ac70ef06165eca43d040dfc0c3064ee69b82b39c86475c6c49b
BLAKE2b-256 checksum
How to use checksums
164e5dc978cc44ec225031c1b7500137af6f99b3eb2cc158b24893789147b0f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

Release files / fs_watcher-1.0.11-py3-none-any.whl

Download URL fs_watcher-1.0.11-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
214a3f9411e4cb87e04463721679e48b1f547de9cc30ffae60cf2f35b3799619
BLAKE2b-256 checksum
How to use checksums
c6c1a886de311f8c1dc303bbf72b7f0daa7180b6c41d949c1b36b00a5fcb39cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

Release history Release notifications | RSS feed

This release

1.0.11 This release

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page