Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zeroXten/consul-do
Do something based on leadership status
https://github.com/zeroXten/consul-do
Last synced: about 1 month ago
JSON representation
Do something based on leadership status
- Host: GitHub
- URL: https://github.com/zeroXten/consul-do
- Owner: zeroXten
- License: mit
- Created: 2014-12-22T13:17:38.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T07:59:20.000Z (over 1 year ago)
- Last Synced: 2024-08-03T02:05:11.220Z (4 months ago)
- Language: Python
- Size: 9.77 KB
- Stars: 58
- Watchers: 9
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-consul - consul-do: Do something based on leadership status
README
consul-do
=========Do something based on leadership status using consul.io
See https://consul.io
Installation
============It's just a python script with no additional modules. Download it and stick it somewhere.
*NOTE* A consul agent is required to be installed where you run this script.
Usage
=====$ consul-do
Usage: consul-do KEY [DEBUG]Useful for running cronjobs in HA mode.
Run something like this on two or more servers:
* * * * * /usr/bin/consul-do JOB-1 && /path/to/job1
*/10 * * * * /usr/bin/consul-do JOB-2 && /path/to/job2Only one of the servers will be elected leader and will therefore run the job. Should the leader fail, a follower will take over.
To enable debug mode, add anything as a second argument. E.g.
$ consul-do JOB-1 debug
Running...
Found nodename: test.internal
Found KV store
Found session: e32c055d-c6ed-e277-45ad-079ba218bb01
Found session node, we're the leader
....If you require a consul ACL
$ CONSUL_HTTP_TOKEN="mytoken" consul-do ...
Testing
=======$ vagrant up
Run the following on each respective server
$ consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -node=agent-one -bind=172.20.20.10
$ consul agent -server -join 172.20.20.10 -data-dir /tmp/consul -node=agent-two -bind=172.20.20.11
$ consul agent -server -join 172.20.20.10 -data-dir /tmp/consul -node=agent-three -bind=172.20.20.12Now you can run a command on each server
$ while true; do /vagrant/consul-do testing && date; sleep 10; done