Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Service monitoring daemon that registers/deregisters servers in Apache ZooKeeper

branch: master

Force requirement of nd_service_registry 0.2.5, and bump ver to 0.3.2.

nd_service_registry has a major bug
(Nextdoor/ndserviceregistry#19) that needs to
be pushed out. This forces new installations of zk_watcher >= 0.3.2 to
get the bug-fixed version of nd_service_registry.

Change-Id: I6f964e0cd6f9dfd95efd9ebd6f4247cdb0fe16b9
latest commit db8f28b7e7
Matt diranged authored August 26, 2013
Octocat-spinner-32 etc Add Gerrit instructions and hooks March 18, 2013
Octocat-spinner-32 extras provide an example zk_watcher upstart job config December 13, 2012
Octocat-spinner-32 zk_watcher Force requirement of nd_service_registry 0.2.5, and bump ver to 0.3.2. August 26, 2013
Octocat-spinner-32 Clean up the docs. October 11, 2012
Octocat-spinner-32 README.rst Fix doc link to etc/ March 18, 2013
Octocat-spinner-32 Force requirement of nd_service_registry 0.2.5, and bump ver to 0.3.2. August 26, 2013
Octocat-spinner-32 zk_watcher.rst Add an [auth] section and the ability to provide a user/password to o… December 13, 2012


zk_watcher is a Python script that handles registration with an Apache ZooKeeper service.

The goal of zk_watcher is to monitor a particular service on a host machine and register that machine as a provider of that service at a given path on the ZooKeeper service.

A simple example is having zk_watcher monitor Apache httpd by running service apache2 status at a regular interval and registers with ZooKeeper at a given path (say /services/production/webservers). As long as the command returns a safe exit code (0), zk_watcher will register with ZooKeeper that this server is providing this particular service. If the hostname of the machine is, the registration path would look like this


In the event that the service check fails, the host will be immediately de- registered from that path.


To install, run

python install


pip install zk_watcher

Service Configs

To configure, edit the '/etc/zk/config.cfg' file. The file consists of sections that each point to a particular service you want to monitor and register with ZooKeeper. An example file is provided, but could look like this

cmd: /etc/init.d/sshd status
refresh: 60
service_port: 22
zookeeper_path: /services/ssh
zookeeper_data: { "foo": "bar", "bah": "humbug" }

cmd: /etc/init.d/apache status
refresh: 60
service_port: 22
zookeeper_path: /services/web
zookeeper_data: foo=bar, bah=humbug


If you wish to create a Digset authentication token and use that for your client session with Zookeeper, you can add the settings to the config file like this

user: username
password: 123456

If you do this, please look at the nd_service_registry docs to understand how the auth token is used, and what permissions are setup by default.

Running it

See the 'zk_watcher.rst' file for configuration and run-time options.


Right now you must install this package as root, or you must create the /etc/zk directory ahead of time and change its ownership to your installation user name. The uses a hard-coded path (/etc/zk/config.cfg) for the config file, and will fail if it cannot create the file at that path. This will be fixed in the next version.

Contributing to this code

Code contributions can be made through the Nextdoor Gerrit Code Review system. In order to contribute, you will want to follow these instructions:

Nextdoor Code Review System

Place the following lines into ~/.ssh/config::

Port 29418

Then verify that you can connect to Gerrit::

$ ssh
****    Welcome to Gerrit Code Review    ****

Hi Matt Wise, you have successfully connected over SSH.

Unfortunately, interactive shells are disabled.
To clone a hosted Git repository, use:

git clone ssh://<YOUR USERNAME>

Connection to closed.

Install and configure git-change::

$ sudo easy_install pip
$ sudo pip install git-change

Clone the repo and setup your hooks::

$ git clone
$ cd zkwatcher
$ etc/

Make your change, and submit it::

$ touch MyFile
$ git add MyFile
$ git change create
Something went wrong with that request. Please try again.