modules/{consul-distributed-services,consul-service-registry}: set CONSUL_HTTP_ADDR
This commit is contained in:
parent
0025a4bb2a
commit
5267d14b48
2 changed files with 9 additions and 0 deletions
|
@ -4,6 +4,9 @@ with lib;
|
|||
|
||||
let
|
||||
consul = config.services.consul.package;
|
||||
|
||||
consulCfg = config.services.consul.extraConfig;
|
||||
consulHttpAddr = "${consulCfg.addresses.http or "127.0.0.1"}:${toString (consulCfg.ports.http or 8500)}";
|
||||
in
|
||||
{
|
||||
options.systemd.services = mkOption {
|
||||
|
@ -36,6 +39,7 @@ in
|
|||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=${consul}/bin/consul lock --name=${n} --n=${toString cfg.replicas} --shell=false --child-exit-code 'services/${n}%i' ${optionalString (cfg.registerService != null) runWithRegistration} ${ExecStart}
|
||||
Environment="CONSUL_HTTP_ADDR=${consulHttpAddr}"
|
||||
${optionalString (v.serviceConfig ? RestrictAddressFamilies) "RestrictAddressFamilies=AF_NETLINK"}
|
||||
${optionalString (cfg.registerService != null) "ExecStopPost=${svc.commands.deregister}"}
|
||||
''))
|
||||
|
|
|
@ -7,13 +7,18 @@ let
|
|||
|
||||
consul = "${config.services.consul.package}/bin/consul";
|
||||
|
||||
consulCfg = config.services.consul.extraConfig;
|
||||
consulHttpAddr = "${consulCfg.addresses.http or "127.0.0.1"}:${toString (consulCfg.ports.http or 8500)}";
|
||||
|
||||
consulRegisterScript = pkgs.writeShellScript "consul-register" ''
|
||||
export CONSUL_HTTP_ADDR='${consulHttpAddr}'
|
||||
while ! ${consul} services register "$1"; do
|
||||
sleep 1
|
||||
done
|
||||
'';
|
||||
|
||||
consulDeregisterScript = pkgs.writeShellScript "consul-deregister" ''
|
||||
export CONSUL_HTTP_ADDR='${consulHttpAddr}'
|
||||
for i in {1..5}; do
|
||||
if ${consul} services deregister "$1"; then
|
||||
break
|
||||
|
|
Loading…
Reference in a new issue