Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add FileWatcher watching a file containing server list. #53
I added a new watcher, FileWatcher, which watches a server-list file. Because this watcher uses Listen gem, changes of the file will be detected immediately with something like inotify.
Why I implemented this
I wrote this watcher for using with Serf. Serf can get join event and leave event. If a event handler of Serf adds (or removes) a server from the file, synapse will adds (or removes) the backend server to haproxy.cfg.
@ryotarai there is a bug here if you aren't explicitly using inotify with the listen gem (and even if you do, it might overflow - I once implemented a filesystem mirror with inotify and in case of very many file changes it would miss some). Here is how it goes:
This means that you might have the file be created by serf at the beginning of the second with 10 servers, and then at the end of the second with 11 servers (for example). If you are polling with stat(2) (default behavior) and not using inotify, then 'listen' will only see one change.
This is how I solved it: