summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/collectd.nix
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/services/monitoring/collectd.nix
parentdc9f69c260139c23fa4944826acc3d46ef1a3237 (diff)
downloadnixpkgs-67340baa9b1093d7551b13e774911076a666f020.tar
nixpkgs-67340baa9b1093d7551b13e774911076a666f020.tar.gz
nixpkgs-67340baa9b1093d7551b13e774911076a666f020.tar.bz2
nixpkgs-67340baa9b1093d7551b13e774911076a666f020.tar.lz
nixpkgs-67340baa9b1093d7551b13e774911076a666f020.tar.xz
nixpkgs-67340baa9b1093d7551b13e774911076a666f020.tar.zst
nixpkgs-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/services/monitoring/collectd.nix')
-rw-r--r--nixos/modules/services/monitoring/collectd.nix37
1 files changed, 8 insertions, 29 deletions
diff --git a/nixos/modules/services/monitoring/collectd.nix b/nixos/modules/services/monitoring/collectd.nix
index 79a8a1ff5ae..eff1aecc910 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;
     };
   };
 }