Skip to content
DawnAAPublic

About

Watchdog: run a subprocess and restart it when the watch file shows no recent activity.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

filedog

filedog is a subprocess watchdog keyed on a watch file’s latest activity timestamp: Unix stat atime, mtime, and ctime—idle time is measured from max(atime, mtime, ctime). When idle exceeds a threshold, the child is killed and optionally restarted after a cooldown. Useful when liveness should follow an external heartbeat file (e.g. client-side fuzzing, long-running workers).

Platforms: Unix only (Linux, *BSD, macOS, …). Building for non-Unix targets fails by design.

Languages: 简体中文

Overview

  • Spawns the command in its own session (setsid) with a dedicated process group so the whole tree can be signalled.
  • Polls the watch file: if now - max(atime, mtime, ctime) >= --timeout, treats as idle—sends SIGTERM to the process group, waits, then SIGKILL if needed; after --delay, may respawn.
  • After each spawn, a --wait grace period runs (only exit detection, no idle logic). With --wait 0, a short ~200ms poll still runs to avoid an exec race where the child is mistaken for hung.
  • --retry limits consecutive idle kills; a poll that sees fresh activity resets the counter.
  • On SIGTERM / SIGINT / SIGHUP, filedog kills the child process group and exits with 128 + signal number.
  • The watch file is created if missing (parent dirs created as needed). It must be a regular file, not a directory.

Requirements & build

  • Rust (stable recommended; edition = "2021")
cargo build --release

Binary: target/release/filedog. Install from the repo root:

cargo install --path .

(Ensure your Cargo bin directory is on PATH.)

Usage

filedog -f <watch-file> [options] -- <command> [args...]

If the command starts with -, put -- before it.

Examples

# Watch .dog: 10s grace after start; 30s idle threshold; 5s cooldown before respawn; --retry 3
filedog -f .dog -w 10 -d 5 -t 30 -r 3 -- ./your-command arg1 arg2

filedog --file .dog --wait 10 --delay 5 --timeout 30 --retry 3 -- ./your-command arg1 arg2

Full CLI details:

cargo run -- --help
# or
./target/release/filedog --help

Options

Option Description
-f, --file PATH Watch file (required). Idle uses max(atime, mtime, ctime).
-w, --wait SEC Grace after each child start (seconds). Default 0 (still includes a short exec race window).
-d, --delay SEC Sleep after an idle kill before respawning. Default 0.
-t, --timeout SEC Idle threshold and poll interval (seconds). Default 30. Must be > 0.
-r, --retry N Max consecutive idle-kill counter before exit 124; reset when a poll sees the watch file “active”. With N=0, exit after the first idle kill (no respawn).
--no-banner Suppress short red stderr lines on idle-driven restarts.
--debug Red stderr logs for [wait] / [delay] / [check].

Linux: relatime and atime

Many systems mount with relatime, so atime may not update on every read. If you rely on read access to refresh idle time, consider:

  • Mounting with strictatime, or
  • Avoiding O_NOATIME on the watch path, or
  • Leaning on mtime/ctime (e.g. periodic touch or writes by the worker).

See in-source comments and NOTES in filedog --help.

Exit codes

Situation Code
Usage/validation errors, fatal spawn/stat failures 2
Idle kills exceeded --retry 124
Child exits on its own Child exit code (or 128 + signal on Unix if killed by signal)
filedog stopped by SIGTERM / SIGINT / SIGHUP 128 + signal number

License

Apache License, Version 2.0.

Crates

  • clap — CLI parsing
  • libc — process groups, kill, setsid, …
  • signal-hook — async signal handling

About

Watchdog: run a subprocess and restart it when the watch file shows no recent activity.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages