2014-05-05 18:58:51 +00:00
|
|
|
{config, pkgs, lib, ...}:
|
2009-11-18 08:39:10 +00:00
|
|
|
|
2018-11-10 00:07:42 +00:00
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.monit;
|
2020-05-10 01:10:06 +00:00
|
|
|
extraConfig = pkgs.writeText "monitConfig" cfg.extraConfig;
|
2009-11-18 08:39:10 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2020-05-10 01:10:06 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "monit" "config" ] ["services" "monit" "extraConfig" ])
|
|
|
|
];
|
|
|
|
|
2018-11-10 00:07:42 +00:00
|
|
|
options.services.monit = {
|
|
|
|
|
|
|
|
enable = mkEnableOption "Monit";
|
|
|
|
|
2020-05-10 01:10:06 +00:00
|
|
|
configFiles = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [];
|
|
|
|
description = "List of paths to be included in the monitrc file";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2018-11-10 00:07:42 +00:00
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2020-05-10 01:10:06 +00:00
|
|
|
description = "Additional monit config as string";
|
2009-11-18 08:39:10 +00:00
|
|
|
};
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2018-11-10 00:07:42 +00:00
|
|
|
config = mkIf cfg.enable {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2017-09-27 22:20:14 +00:00
|
|
|
environment.systemPackages = [ pkgs.monit ];
|
|
|
|
|
2019-08-13 21:52:01 +00:00
|
|
|
environment.etc.monitrc = {
|
2020-05-10 01:10:06 +00:00
|
|
|
text = concatMapStringsSep "\n" (path: "include ${path}") (cfg.configFiles ++ [extraConfig]);
|
2018-03-28 21:45:57 +00:00
|
|
|
mode = "0400";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services.monit = {
|
2016-09-12 14:31:18 +00:00
|
|
|
description = "Pro-active monitoring utility for unix systems";
|
|
|
|
after = [ "network.target" ];
|
2016-01-06 06:50:18 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-12 14:31:18 +00:00
|
|
|
serviceConfig = {
|
2017-09-27 22:20:14 +00:00
|
|
|
ExecStart = "${pkgs.monit}/bin/monit -I -c /etc/monitrc";
|
|
|
|
ExecStop = "${pkgs.monit}/bin/monit -c /etc/monitrc quit";
|
|
|
|
ExecReload = "${pkgs.monit}/bin/monit -c /etc/monitrc reload";
|
2016-09-12 14:31:18 +00:00
|
|
|
KillMode = "process";
|
|
|
|
Restart = "always";
|
|
|
|
};
|
2019-08-13 21:52:01 +00:00
|
|
|
restartTriggers = [ config.environment.etc.monitrc.source ];
|
2009-11-18 08:39:10 +00:00
|
|
|
};
|
2018-03-28 21:45:57 +00:00
|
|
|
|
2009-11-18 08:39:10 +00:00
|
|
|
};
|
|
|
|
}
|