at 15.09-beta 3.0 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.bosun; 7 8 configFile = pkgs.writeText "bosun.conf" '' 9 tsdbHost = ${cfg.opentsdbHost} 10 httpListen = ${cfg.listenAddress} 11 stateFile = ${cfg.stateFile} 12 checkFrequency = 5m 13 14 ${cfg.extraConfig} 15 ''; 16 17in { 18 19 options = { 20 21 services.bosun = { 22 23 enable = mkOption { 24 type = types.bool; 25 default = false; 26 description = '' 27 Whether to run bosun. 28 ''; 29 }; 30 31 package = mkOption { 32 type = types.package; 33 example = literalExample "pkgs.bosun"; 34 description = '' 35 bosun binary to use. 36 ''; 37 }; 38 39 user = mkOption { 40 type = types.string; 41 default = "bosun"; 42 description = '' 43 User account under which bosun runs. 44 ''; 45 }; 46 47 group = mkOption { 48 type = types.string; 49 default = "bosun"; 50 description = '' 51 Group account under which bosun runs. 52 ''; 53 }; 54 55 opentsdbHost = mkOption { 56 type = types.string; 57 default = "localhost:4242"; 58 description = '' 59 Host and port of the OpenTSDB database that stores bosun data. 60 ''; 61 }; 62 63 listenAddress = mkOption { 64 type = types.string; 65 default = ":8070"; 66 description = '' 67 The host address and port that bosun's web interface will listen on. 68 ''; 69 }; 70 71 stateFile = mkOption { 72 type = types.string; 73 default = "/var/lib/bosun/bosun.state"; 74 description = '' 75 Path to bosun's state file. 76 ''; 77 }; 78 79 extraConfig = mkOption { 80 type = types.string; 81 default = ""; 82 description = '' 83 Extra configuration options for Bosun. You should describe your 84 desired templates, alerts, macros, etc through this configuration 85 option. 86 87 A detailed description of the supported syntax can be found at-spi2-atk 88 http://bosun.org/configuration.html 89 ''; 90 }; 91 92 }; 93 94 }; 95 96 config = mkIf cfg.enable { 97 98 services.bosun.package = mkDefault pkgs.bosun; 99 100 systemd.services.bosun = { 101 description = "bosun metrics collector (part of Bosun)"; 102 wantedBy = [ "multi-user.target" ]; 103 104 preStart = 105 '' 106 mkdir -p `dirname ${cfg.stateFile}`; 107 touch ${cfg.stateFile} 108 touch ${cfg.stateFile}.tmp 109 110 if [ "$(id -u)" = 0 ]; then 111 chown ${cfg.user}:${cfg.group} ${cfg.stateFile} 112 chown ${cfg.user}:${cfg.group} ${cfg.stateFile}.tmp 113 fi 114 ''; 115 116 serviceConfig = { 117 PermissionsStartOnly = true; 118 User = cfg.user; 119 Group = cfg.group; 120 ExecStart = '' 121 ${cfg.package}/bin/bosun -c ${configFile} 122 ''; 123 }; 124 }; 125 126 users.extraUsers.bosun = { 127 description = "bosun user"; 128 group = "bosun"; 129 uid = config.ids.uids.bosun; 130 }; 131 132 users.extraGroups.bosun.gid = config.ids.gids.bosun; 133 134 }; 135 136}