You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-3Lines changed: 31 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,12 @@ Consul based leader election with tagging support and hooks
11
11
12
12
Consul lacks a built-in feature for leader election among registered services. This tool is designed to fill that gap. It functions by designating a leader among multiple services, marking the chosen leader with a specified tag. Additionally, it allows for the execution of a script whenever a leader election occurs.
13
13
14
-
### How do I test it?
14
+
### How does it work?
15
+
16
+
Ballot uses Consul's session API to create a session for each service. The session is then used to create a lock on a key. The service that successfully creates the lock is elected as the leader. The leader is then tagged with a specified tag. The leader election is monitored and the leader is updated if the current leader is no longer healthy.
17
+
More info about the sessions here [https://developer.hashicorp.com/consul/tutorials/developer-configuration/application-leader-elections](https://developer.hashicorp.com/consul/tutorials/developer-configuration/application-leader-elections).
18
+
19
+
### How do I use it?
15
20
16
21
1. Install Ballot
17
22
```bash
@@ -53,10 +58,33 @@ $PORT # Port of the service
53
58
$SESSIONID# Current SessionID of the elected master
54
59
```
55
60
61
+
### Configuration
62
+
63
+
The configuration file is a yaml file with the following structure:
64
+
65
+
```yaml
66
+
consul:
67
+
token: # Consul token
68
+
election:
69
+
enabled:
70
+
- my-service-name # Name of the service enabled for election
71
+
services:
72
+
my-service-name: # Name of the service
73
+
id: my-service-name # ID of the service
74
+
key: my-service-name # Key to be used for the lock in Consul, this should be the same across all nodes
75
+
token: # Token to be used for the session in Consul
76
+
serviceChecks: # List of checks to be used to determine the health of the service
77
+
- ping # Name of the check
78
+
primaryTag: primary # Tag to be used to mark the leader
79
+
execOnPromote: '/bin/echo primary'# Command to be executed when the service is elected as leader
80
+
execOnDemote: '/bin/echo secondary'# Command to be executed when the service is demoted as leader
81
+
ttl: 10s# TTL for the session
82
+
lockDelay: 5s# Lock delay for the session
83
+
```
84
+
56
85
### TODO:
57
86
58
-
- Write tests
87
+
- Write more tests
59
88
- Add more examples
60
-
- Re-enable the hooks on state change
61
89
- Allow to pre-define the preferred leader
62
90
- Update the docks with the lock delays and timeouts
0 commit comments