Backend Development 8 min read

Using inotify in Go for Configuration File Hot Reload

This tutorial explains Linux inotify's event model and demonstrates how to employ the Go package golang.org/x/sys/unix to initialize inotify, add watches, and process file system events in order to achieve automatic configuration file hot‑reloading in Go applications.

360 Tech Engineering
360 Tech Engineering
360 Tech Engineering
Using inotify in Go for Configuration File Hot Reload

In this article we introduce Linux inotify, its supported events, and how to use it in Go to implement configuration file hot‑reload.

Inotify, added in Linux kernel 2.6.13, provides inode‑based monitoring of file system changes such as access, modify, create, delete, and move, and can be used with select , poll , or epoll .

Common inotify events (IN_ACCESS, IN_ATTRIB, IN_CLOSE_WRITE, IN_CLOSE_NOWRITE, IN_CREATE, IN_DELETE, IN_DELETE_SELF, IN_MODIFY, IN_MOVE_SELF, IN_MOVED_FROM, IN_MOVED_TO, IN_ALL_EVENTS, IN_OPEN, IN_CLOSE, IN_MOVE) are listed with brief descriptions.

Using the Go package golang.org/x/sys/unix we initialize inotify with InotifyInit() , add a watch on the configuration file via InotifyAddWatch() (watching for IN_CLOSE_WRITE ), and read events in a goroutine using unix.Read() , forwarding them to an events channel.

The article provides a simple Go demo (shown as images) and suggests wrapping the logic into a reusable Watcher struct, with links to open‑source implementations such as watcher.go , goinbox/inotify , and fsnotify for cross‑platform monitoring.

Finally, it notes that inotify is Linux‑only; macOS uses FSEvents and Windows uses FindFirstChangeNotificationA, and recommends fsnotify for cross‑platform needs.

GoLinuxhot reloadinotifyfile monitoring
360 Tech Engineering
Written by

360 Tech Engineering

Official tech channel of 360, building the most professional technology aggregation platform for the brand.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.