Use Consul config format to register/keep-alive/deregister Consul services & checks.
Project description
Service announcer for Consul.
Functionality:
Register/deregister services with checks
Spawn a subprocess
Periodically mark all TTL checks as passed (if any)
Install
For regular usage:
pip install consul-announcer # or add it as a requirement
Usage
consul-announcer --config=path [-h] [--agent=hostname[:port]] [--interval=seconds] [--verbose] -- command [arguments]
Arguments:
-h, --help show this help message and exit
--agent hostname[:port] Consul agent address: hostname[:port]. Default: localhost (default port is 8500)
--config path Consul checks configuration file
--interval seconds interval for periodic marking all TTL checks as passed (should be less than min TTL)
--verbose, -v verbose output. You can specify -v or -vv
Minimal usage:
consul-announcer --config=conf.json -- some-process --with --arguments
--config
It should be a JSON file that contains {"service": {...}} or {"services": [...]}.
Read Consul docs about services definition.
All the services & checks will be registered on process start and deregistered on process termination.
--interval
In the example above, the interval is not specified so it’ll be calculated as min TTL / 10 (if there are TTL checks specified in the config file). But you can provide your own value (in seconds):
consul-announcer --interval=3 ...
If there are no TTL checks and no --interval - an error will raise.
--address
Default agent address is localhost (with default port 8500). You can provide your own:
consul-announcer --agent=1.2.3.4:5678 ...
--verbose
Output levels:
by default only errors and warnings are printed
-v will show info messages
-vv will show info and debug messages
Usage in Python code
from announcer.service import Service
service = Service('localhost:1234', '/path/to/config.json', ['sleep', '5'], 0.5)
service.run()
Development
Install
git clone <this-repo>
cd consul-announcer
pip install -r requirements/test.txt -e .
Test
Test configuration is defined in the tox.ini file and includes py.test tests and flake8 source code checker. You can run all of the tests:
python setup.py test
To run just the py.test tests, not flake8, and to re-use the current virtualenv:
py.test
Release
Tests must be passing
Don’t forget to test all added functionality
Update CHANGELOG with the release info
Update README (if necessary)
Commit all the changes
Create new version tag (e.g.): v1.2.3
Push commits and tags
Release new version on PyPI
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.