modules/consul-service-registry: limit number of retries for deregister

This commit is contained in:
Max Headroom 2023-08-27 16:40:11 +02:00
parent f423f868c5
commit 2ff899cd3e

View file

@ -7,15 +7,20 @@ let
consul = "${config.services.consul.package}/bin/consul"; consul = "${config.services.consul.package}/bin/consul";
writeLoopScript = name: cmd: pkgs.writeShellScript name '' consulRegisterScript = pkgs.writeShellScript "consul-register" ''
while ! ${cmd}; do while ! ${consul} services register "$1"; do
sleep 1 sleep 1
done done
''; '';
consulRegisterScript = writeLoopScript "consul-register" ''${consul} services register "$1"''; consulDeregisterScript = pkgs.writeShellScript "consul-deregister" ''
for i in {1..5}; do
consulDeregisterScript = writeLoopScript "consul-deregister" ''${consul} services deregister "$1"''; if ${consul} services deregister "$1"; then
break
fi
sleep 1
done
'';
register = servicesJson: "${consulRegisterScript} ${servicesJson}"; register = servicesJson: "${consulRegisterScript} ${servicesJson}";