Split off init routine and prevent a few loops.

While here, add a method for waiting indefinitely for the master
election to stop.
Add a test client binary.

Essentially, it’s a binary which just runs master election and prints
the result to stdout.