Merge pull request #8227 from offlinehacker/nixos/consul/alerts-fix

nixos/consul: fix consul alerts enable
This commit is contained in:
Jaka Hudoklin 2015-06-08 14:34:48 +02:00
commit a5d0ac2003
1 changed files with 100 additions and 89 deletions

View File

@ -106,6 +106,12 @@ in
alerts = { alerts = {
enable = mkEnableOption "Whether to enable consul-alerts"; enable = mkEnableOption "Whether to enable consul-alerts";
package = mkOption {
description = "Package to use for consul-alerts.";
default = pkgs.consul-alerts;
type = types.package;
};
listenAddr = mkOption { listenAddr = mkOption {
description = "Api listening address."; description = "Api listening address.";
default = "localhost:9000"; default = "localhost:9000";
@ -135,7 +141,8 @@ in
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable (
mkMerge [{
users.extraUsers."consul" = { users.extraUsers."consul" = {
description = "Consul agent daemon user"; description = "Consul agent daemon user";
@ -207,8 +214,10 @@ in
echo "}" >> /etc/consul-addrs.json echo "}" >> /etc/consul-addrs.json
''; '';
}; };
}
systemd.services.consul-alerts = mkIf (cfg.alerts.enable) { (mkIf (cfg.alerts.enable) {
systemd.services.consul-alerts = {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "consul.service" ]; after = [ "consul.service" ];
@ -216,15 +225,17 @@ in
serviceConfig = { serviceConfig = {
ExecStart = '' ExecStart = ''
${pkgs.consul-alerts}/bin/consul-alerts start \ ${cfg.alerts.package}/bin/consul-alerts start \
--alert-addr=${cfg.alerts.listenAddr} \ --alert-addr=${cfg.alerts.listenAddr} \
--consul-addr=${cfg.alerts.consulAddr} \ --consul-addr=${cfg.alerts.consulAddr} \
${optionalString cfg.alerts.watchChecks "--watch-checks"} \ ${optionalString cfg.alerts.watchChecks "--watch-checks"} \
${optionalString cfg.alerts.watchEvents "--watch-events"} ${optionalString cfg.alerts.watchEvents "--watch-events"}
''; '';
User = if cfg.dropPrivileges then "consul" else null; User = if cfg.dropPrivileges then "consul" else null;
Restart = "on-failure";
}; };
}; };
})
}; ]);
} }