about summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/collectd.nix
diff options
context:
space:
mode:
authorJaka Hudoklin <jakahudoklin@gmail.com>2014-09-17 19:20:12 +0200
committerJaka Hudoklin <jakahudoklin@gmail.com>2014-09-17 19:21:05 +0200
commit9c3c7a75d3a5969bd89922a67f28c3d760f4b796 (patch)
tree21ca526c1aef3dbd7fc7312931b67ad7cbec73d5 /nixos/modules/services/monitoring/collectd.nix
parente6b9656e24f9e38654e20681fbef9bac86edc1bb (diff)
downloadnixlib-9c3c7a75d3a5969bd89922a67f28c3d760f4b796.tar
nixlib-9c3c7a75d3a5969bd89922a67f28c3d760f4b796.tar.gz
nixlib-9c3c7a75d3a5969bd89922a67f28c3d760f4b796.tar.bz2
nixlib-9c3c7a75d3a5969bd89922a67f28c3d760f4b796.tar.lz
nixlib-9c3c7a75d3a5969bd89922a67f28c3d760f4b796.tar.xz
nixlib-9c3c7a75d3a5969bd89922a67f28c3d760f4b796.tar.zst
nixlib-9c3c7a75d3a5969bd89922a67f28c3d760f4b796.zip
collectd: add pidFile option, change default pid to /var/run/collectd.pid
Diffstat (limited to 'nixos/modules/services/monitoring/collectd.nix')
-rw-r--r--nixos/modules/services/monitoring/collectd.nix20
1 files changed, 16 insertions, 4 deletions
diff --git a/nixos/modules/services/monitoring/collectd.nix b/nixos/modules/services/monitoring/collectd.nix
index 6da92db7e5f5..717c2c481683 100644
--- a/nixos/modules/services/monitoring/collectd.nix
+++ b/nixos/modules/services/monitoring/collectd.nix
@@ -7,7 +7,7 @@ let
 
   conf = pkgs.writeText "collectd.conf" ''
     BaseDir "${cfg.dataDir}"
-    PIDFile "${cfg.dataDir}/collectd.pid"
+    PIDFile "${cfg.pidFile}"
     AutoLoadPlugin ${if cfg.autoLoadPlugin then "true" else "false"}
     Hostname ${config.networking.hostName}
 
@@ -50,6 +50,14 @@ in {
       type = path;
     };
 
+    pidFile = mkOption {
+      default = "/var/run/collectd.pid";
+      description = ''
+        Location of collectd pid file.
+      '';
+      type = path;
+    };
+
     autoLoadPlugin = mkOption {
       default = false;
       description = ''
@@ -83,16 +91,20 @@ in {
       wantedBy = [ "multi-user.target" ];
 
       serviceConfig = {
-        ExecStart = "${pkgs.collectd}/sbin/collectd -C ${conf} -P ${cfg.dataDir}/collectd.pid";
+        ExecStart = "${pkgs.collectd}/sbin/collectd -C ${conf} -P ${cfg.pidFile}";
         Type = "forking";
-        PIDFile = "${cfg.dataDir}/collectd.pid";
+        PIDFile = cfg.pidFile;
         User = optional (cfg.user!="root") cfg.user;
         PermissionsStartOnly = true;
       };
 
       preStart = ''
         mkdir -m 0700 -p ${cfg.dataDir}
-        if [ "$(id -u)" = 0 ]; then chown -R ${cfg.user} ${cfg.dataDir}; fi
+        install -D /dev/null ${cfg.pidFile}
+        if [ "$(id -u)" = 0 ]; then
+          chown -R ${cfg.user} ${cfg.dataDir};
+          chown ${cfg.user} ${cfg.pidFile}
+        fi
       '';
     };