From a17f5c8c9bfa58a9bdd578971b13d2aa1b2024d1 Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Thu, 12 Feb 2015 19:15:23 +0100 Subject: [PATCH] nixos/consul: add consul-alerts service --- nixos/modules/services/networking/consul.nix | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/nixos/modules/services/networking/consul.nix b/nixos/modules/services/networking/consul.nix index b2d5854fbc0c..3ae010e81070 100644 --- a/nixos/modules/services/networking/consul.nix +++ b/nixos/modules/services/networking/consul.nix @@ -122,6 +122,34 @@ in ''; }; + alerts = { + enable = mkEnableOption "Whether to enable consul-alerts"; + + listenAddr = mkOption { + description = "Api listening address."; + default = "localhost:9000"; + type = types.str; + }; + + consulAddr = mkOption { + description = "Consul api listening adddress"; + default = "localhost:8500"; + type = types.str; + }; + + watchChecks = mkOption { + description = "Whether to enable check watcher."; + default = true; + type = types.bool; + }; + + watchEvents = mkOption { + description = "Whether to enable event watcher."; + default = true; + type = types.bool; + }; + }; + }; }; @@ -204,5 +232,23 @@ in ''; }; + systemd.services.consul-alerts = mkIf (cfg.alerts.enable) { + wantedBy = [ "multi-user.target" ]; + after = [ "consul.service" ]; + + path = [ pkgs.consul ]; + + serviceConfig = { + ExecStart = '' + ${pkgs.consul-alerts}/bin/consul-alerts start \ + --alert-addr=${cfg.alerts.listenAddr} \ + --consul-addr=${cfg.alerts.consulAddr} \ + ${optionalString cfg.alerts.watchChecks "--watch-checks"} \ + ${optionalString cfg.alerts.watchEvents "--watch-events"} + ''; + User = if cfg.dropPrivileges then "consul" else null; + }; + }; + }; }