From c3a09bb3fbc5388c0a10647df5098cf0a402fcdf Mon Sep 17 00:00:00 2001 From: Juliano Martinez Date: Tue, 23 Jan 2024 21:02:05 +0100 Subject: [PATCH] adds init script for multi and single service and update readme --- README.md | 7 ++----- init/ballot.service | 26 ++++++++++++++++++++++++++ init/ballot@.service | 26 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 init/ballot.service create mode 100644 init/ballot@.service diff --git a/README.md b/README.md index b5756da..8edd454 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,10 @@ ## Ballot -Consul service election with tagging support and hooks +Consul based leader election with tagging support and hooks ### What is it? -Consul doesn't support leader election for registered services. This tool is meant to help with that. -The idea is that you have multiple services and you need to select a leader. It will apply a tag of choise -to the leader and when a election happens you can hook a script execution. -This tool can be very useful for setups that require a leader service, but do not offer a leader election out of the box. +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. ### How do I test it? diff --git a/init/ballot.service b/init/ballot.service new file mode 100644 index 0000000..4145d4c --- /dev/null +++ b/init/ballot.service @@ -0,0 +1,26 @@ +[Unit] +Description=Consul based leader election with tagging support and hooks +After=network.target local-fs.target remote-fs.target nss-lookup.target time-sync.target + +[Service] +User=ballot +Group=ballot +ProtectSystem=full +PrivateTmp=yes +PrivateDevices=yes +EnvironmentFile=-/etc/sysconfig/ballot +ExecStart=/usr/bin/ballot run --config=/etc/ballot/ballot.yaml $CMD_OPTS +ExecReload=/bin/kill -s HUP $MAINPID +KillMode=process +KillSignal=SIGINT +Restart=on-failure +RestartSec=5 +TimeoutStopSec=30 +StartLimitInterval=60 +StartLimitBurst=3 +LimitNOFILE=65536 +LimitMEMLOCK=infinity +SyslogIdentifier=ballot + +[Install] +WantedBy=multi-user.target diff --git a/init/ballot@.service b/init/ballot@.service new file mode 100644 index 0000000..8303cf5 --- /dev/null +++ b/init/ballot@.service @@ -0,0 +1,26 @@ +[Unit] +Description=Consul based leader election with tagging support and hooks +After=network.target local-fs.target remote-fs.target nss-lookup.target time-sync.target + +[Service] +User=ballot +Group=ballot +ProtectSystem=full +PrivateTmp=yes +PrivateDevices=yes +EnvironmentFile=-/etc/sysconfig/ballot-%i +ExecStart=/usr/bin/ballot run --config=/etc/ballot/%i.yaml $CMD_OPTS +ExecReload=/bin/kill -s HUP $MAINPID +KillMode=process +KillSignal=SIGINT +Restart=on-failure +RestartSec=5 +TimeoutStopSec=30 +StartLimitInterval=60 +StartLimitBurst=3 +LimitNOFILE=65536 +LimitMEMLOCK=infinity +SyslogIdentifier=ballot-%i + +[Install] +WantedBy=multi-user.target