diff options
author | William A. Kennington III <william@wkennington.com> | 2014-12-08 13:55:12 -0800 |
---|---|---|
committer | William A. Kennington III <william@wkennington.com> | 2014-12-09 02:24:36 -0800 |
commit | c17eb7f0e60dbf1ced73f8637e987fda2547206f (patch) | |
tree | aed623a182a00fc1aedd669b80bb4e98a5de7dee /nixos | |
parent | 765eab6d5b09af74b9d644c3953c40eebf98de63 (diff) | |
download | nixlib-c17eb7f0e60dbf1ced73f8637e987fda2547206f.tar nixlib-c17eb7f0e60dbf1ced73f8637e987fda2547206f.tar.gz nixlib-c17eb7f0e60dbf1ced73f8637e987fda2547206f.tar.bz2 nixlib-c17eb7f0e60dbf1ced73f8637e987fda2547206f.tar.lz nixlib-c17eb7f0e60dbf1ced73f8637e987fda2547206f.tar.xz nixlib-c17eb7f0e60dbf1ced73f8637e987fda2547206f.tar.zst nixlib-c17eb7f0e60dbf1ced73f8637e987fda2547206f.zip |
nixos/consul: Make service definition more sane
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/services/networking/consul.nix | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/nixos/modules/services/networking/consul.nix b/nixos/modules/services/networking/consul.nix index ebc836814089..c5f5bd79c1a9 100644 --- a/nixos/modules/services/networking/consul.nix +++ b/nixos/modules/services/networking/consul.nix @@ -8,7 +8,6 @@ let configOptions = { data_dir = dataDir; - rejoin_after_leave = true; } // (if cfg.webUi then { ui_dir = "${pkgs.consul.ui}"; } else { }) // cfg.extraConfig; @@ -41,6 +40,35 @@ in ''; }; + leaveOnStop = mkOption { + type = types.bool; + default = false; + description = '' + If enabled, causes a leave action to be sent when closing consul. + This allows a clean termination of the node, but permanently removes + it from the cluster. You probably don't want this option unless you + are running a node which going offline in a permanent / semi-permanent + fashion. + ''; + }; + + joinNodes = mkOption { + type = types.listOf types.str; + default = [ ]; + description = '' + A list of addresses of nodes which should be joined at startup if the + current node is in a left state. + ''; + }; + + joinRetries = mkOption { + type = types.int; + default = 10; + description = '' + The number of times to retry connecting to the join nodes. + ''; + }; + interface = { advertise = mkOption { @@ -119,13 +147,14 @@ in serviceConfig = { ExecStart = "@${pkgs.consul}/bin/consul consul agent" + concatMapStrings (n: " -config-file ${n}") configFiles; - ExecStop = "${pkgs.consul}/bin/consul leave"; ExecReload = "${pkgs.consul}/bin/consul reload"; PermissionsStartOnly = true; User = if cfg.dropPrivileges then "consul" else null; - }; + } // (optionalAttrs (cfg.leaveOnStop) { + ExecStop = "${pkgs.consul}/bin/consul leave"; + }); - path = with pkgs; [ iproute gnugrep gawk ]; + path = with pkgs; [ iproute gnugrep gawk consul ]; preStart = '' mkdir -m 0700 -p ${dataDir} chown -R consul ${dataDir} @@ -160,6 +189,18 @@ in echo " \"\": \"\"" >> /etc/consul-addrs.json echo "}" >> /etc/consul-addrs.json ''; + postStart = '' + # Issues joins to nodes which we statically connect to + ${flip concatMapStrings cfg.joinNodes (addr: '' + for i in {0..${toString cfg.joinRetries}}; do + # Try to join the other nodes ${toString cfg.joinRetries} times before failing + consul join "${addr}" && break + sleep 1 + done & + '')} + wait + exit 0 + ''; }; }; |