gomon is a minimalist, dependency-free (aside from a filesystem watcher), and highly efficient file watcher and process restarter built in Go. It's designed to monitor local file changes and automatically restart your command without relying on bulky external tooling.
gomon is easily installed using the standard Go toolchain.
go install github.com/audinue/gomon@latestEnsure your GOPATH/bin directory is in your system's PATH to run the command directly.
gomon was created to provide a precise and robust process supervision tool based entirely on the Go standard library and native Unix system calls, adhering to the philosophy of "Do the Right Things."
- Minimal Footprint: No heavy dependencies—only a reliable file system watcher (
github.com/rjeczalik/notify) is used. - Clean Process Killing: It uses Process Group Isolation (
Setpgid: true) andSIGTERMto the Process Group ID (-PGID) to ensure your target process and all its child processes are cleanly terminated before a restart, avoiding orphaned processes. - Built-in Debouncing: Implements a state-of-the-art
time.Timermechanism (Go 1.23+ idiom) for precise debounce, preventing rapid restarts from multiple simultaneous file saves.
Simply prefix the command you wish to monitor with gomon.
To watch for changes and automatically restart a Go application:
gomon go run hello-world.goYou can use gomon to watch files and restart any script or executable:
gomon ./server-build --port 8080
# or for a simple script:
gomon bash script.sh-
Watch:
gomonstarts watching the current directory (./...) forCreate,Write, andRemoveevents. - Start: The target command is executed in a new isolated Process Group.
- Debounce: Upon detecting a file event, a timer is reset (currently set to 16ms).
-
Restart: If no further file events occur before the timer expires, the
Process.Stop()method sends aSIGTERMsignal to the entire Process Group, waits for it to terminate, and then executesProcess.Start()to launch the command again. -
Graceful Exit: Pressing
$\text{CTRL}+\text{C}$ sends aSIGINTtogomon, which then gracefully terminates the monitored process group before exiting itself.
The core logic of process management is encapsulated in the Process struct and uses the following primitives:
syscall.SysProcAttr{Setpgid: true}: Creates a new Process Group for the target command.syscall.Kill(-pgid, syscall.SIGTERM): Ensures a full, clean shutdown of the process and its children.errors.Join(p.Stop(), p.Start()): TheRestart()function handles and reports combined errors from the stop and start operations, prioritizing continuous supervision.
This README was written by Gemini 2.5 Flash