1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7let
8 cfg = config.services.monit;
9in
10
11{
12 options.services.monit = {
13
14 enable = lib.mkEnableOption "Monit";
15
16 config = lib.mkOption {
17 type = lib.types.lines;
18 default = "";
19 description = "monitrc content";
20 };
21
22 };
23
24 config = lib.mkIf cfg.enable {
25
26 environment.systemPackages = [ pkgs.monit ];
27
28 environment.etc.monitrc = {
29 text = cfg.config;
30 mode = "0400";
31 };
32
33 systemd.services.monit = {
34 description = "Pro-active monitoring utility for unix systems";
35 after = [ "network.target" ];
36 wantedBy = [ "multi-user.target" ];
37 serviceConfig = {
38 ExecStart = "${pkgs.monit}/bin/monit -I -c /etc/monitrc";
39 ExecStop = "${pkgs.monit}/bin/monit -c /etc/monitrc quit";
40 ExecReload = "${pkgs.monit}/bin/monit -c /etc/monitrc reload";
41 KillMode = "process";
42 Restart = "always";
43 };
44 restartTriggers = [ config.environment.etc.monitrc.source ];
45 };
46
47 };
48
49 meta.maintainers = with lib.maintainers; [ ryantm ];
50}