It is a common requirement that you want to setup a Zope cluster with zeo server, zeo instances and haproxy based on some common port base that you want to define once in your buildout configuration and perform all other ports based on the port base.
For ZEO clients there is the port-base configuration option which works fine.
For ZEO servers you can only hard-code the zeo server's port - no option to calculate it or configure it in your buildout configuration
For HAproxy you need to generate the haproxy.conf file e.g. using collective.recipe.template which also does not seem to provide an option to perform calculations.
What I basically want is to provide a port base for all services and configure all other ports of a cluster as offset once. Any idea?
Unfortunately I don't have an nice solution lying around.
When I did hosting I had a custom configuration management tool that would generate a buildout with the correct services and ports mapping for our whole platform.
You could use buildout to generate the configs needed and then use sed to tweak the configs to your needs.
ie, use 123 to prefix the ports and then replace that with the base port. This won't help you when the ports need to wrap around, ie zeoclients ranging from 999-1010.
An alternative might be to use a container (docker, vps, or vm ), where you can use a known set of ports and map them on the host.
Some more praise for mr.scripty, we use it to extract the value of a version.txt in our buildout repository (managed by zest.releaser) and have it available as a variable.
recipe = mr.scripty
version =
import os
bodir = self.buildout['buildout']['directory']
versionfile = os.path.join(bodir, 'version.txt')
if os.path.exists(versionfile):
with open(versionfile, 'r') as infile:
version = infile.readline().strip()
else:
version = 'unknown'
return version
Then we inject the version in zeoclients sentry config so each reported stack trace has the buildout release included. Mr.scripty is very useful for simple glueing.