summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorVolth <volth@webmaster.ms>2017-06-30 00:44:03 +0000
committerVolth <volth@webmaster.ms>2017-06-30 00:52:22 +0000
commit67340baa9b1093d7551b13e774911076a666f020 (patch)
tree3a261adcc496ab845daf999c02e38e5f3d7425dc /nixos/modules
parentdc9f69c260139c23fa4944826acc3d46ef1a3237 (diff)
downloadnixlib-67340baa9b1093d7551b13e774911076a666f020.tar
nixlib-67340baa9b1093d7551b13e774911076a666f020.tar.gz
nixlib-67340baa9b1093d7551b13e774911076a666f020.tar.bz2
nixlib-67340baa9b1093d7551b13e774911076a666f020.tar.lz
nixlib-67340baa9b1093d7551b13e774911076a666f020.tar.xz
nixlib-67340baa9b1093d7551b13e774911076a666f020.tar.zst
nixlib-67340baa9b1093d7551b13e774911076a666f020.zip
collectd service: minor refactoring
* removed pid-file support, it is needless to run collectd as systemd service
* removed static user id, as all the files reowned on the service start
* added ambient capabilities for ping and smart (hdd health) functions
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/misc/ids.nix2
-rw-r--r--nixos/modules/services/monitoring/collectd.nix37
2 files changed, 9 insertions, 30 deletions
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix
index 22059bb7fbbb..5ac5764cd7cb 100644
--- a/nixos/modules/misc/ids.nix
+++ b/nixos/modules/misc/ids.nix
@@ -166,7 +166,7 @@
       dnsmasq = 141;
       uhub = 142;
       yandexdisk = 143;
-      collectd = 144;
+      #collectd = 144; #unused
       consul = 145;
       mailpile = 146;
       redmine = 147;
diff --git a/nixos/modules/services/monitoring/collectd.nix b/nixos/modules/services/monitoring/collectd.nix
index 79a8a1ff5aed..eff1aecc9108 100644
--- a/nixos/modules/services/monitoring/collectd.nix
+++ b/nixos/modules/services/monitoring/collectd.nix
@@ -7,7 +7,6 @@ let
 
   conf = pkgs.writeText "collectd.conf" ''
     BaseDir "${cfg.dataDir}"
-    PIDFile "${cfg.pidFile}"
     AutoLoadPlugin ${boolToString cfg.autoLoadPlugin}
     Hostname "${config.networking.hostName}"
 
@@ -26,13 +25,7 @@ let
 
 in {
   options.services.collectd = with types; {
-    enable = mkOption {
-      default = false;
-      description = ''
-        Whether to enable collectd agent.
-      '';
-      type = bool;
-    };
+    enable = mkEnableOption "collectd agent";
 
     package = mkOption {
       default = pkgs.collectd;
@@ -59,14 +52,6 @@ in {
       type = path;
     };
 
-    pidFile = mkOption {
-      default = "/var/run/collectd.pid";
-      description = ''
-        Location of collectd pid file.
-      '';
-      type = path;
-    };
-
     autoLoadPlugin = mkOption {
       default = false;
       description = ''
@@ -100,27 +85,21 @@ in {
       wantedBy = [ "multi-user.target" ];
 
       serviceConfig = {
-        ExecStart = "${cfg.package}/sbin/collectd -C ${conf} -P ${cfg.pidFile}";
-        Type = "forking";
-        PIDFile = cfg.pidFile;
-        User = optional (cfg.user!="root") cfg.user;
+        ExecStart = "${cfg.package}/sbin/collectd -C ${conf} -f";
+        User = cfg.user;
+        AmbientCapabilities = "cap_net_raw cap_dac_override"; # cap_net_raw for ping, cap_dac_override for smart
         PermissionsStartOnly = true;
       };
 
       preStart = ''
-        mkdir -p ${cfg.dataDir}
-        chmod 755 ${cfg.dataDir}
-        install -D /dev/null ${cfg.pidFile}
-        if [ "$(id -u)" = 0 ]; then
-          chown -R ${cfg.user} ${cfg.dataDir};
-          chown ${cfg.user} ${cfg.pidFile}
-        fi
+        mkdir -p "${cfg.dataDir}"
+        chmod 755 "${cfg.dataDir}"
+        chown -R ${cfg.user} "${cfg.dataDir}"
       '';
-    }; 
+    };
 
     users.extraUsers = optional (cfg.user == "collectd") {
       name = "collectd";
-      uid = config.ids.uids.collectd;
     };
   };
 }