collectd: add pidFile option, change default pid to /var/run/collectd.pid

+16 -4
+16 -4
nixos/modules/services/monitoring/collectd.nix
··· 7 7 8 8 conf = pkgs.writeText "collectd.conf" '' 9 9 BaseDir "${cfg.dataDir}" 10 - PIDFile "${cfg.dataDir}/collectd.pid" 10 + PIDFile "${cfg.pidFile}" 11 11 AutoLoadPlugin ${if cfg.autoLoadPlugin then "true" else "false"} 12 12 Hostname ${config.networking.hostName} 13 13 ··· 46 46 default = "/var/lib/collectd"; 47 47 description = '' 48 48 Data directory for collectd agent. 49 + ''; 50 + type = path; 51 + }; 52 + 53 + pidFile = mkOption { 54 + default = "/var/run/collectd.pid"; 55 + description = '' 56 + Location of collectd pid file. 49 57 ''; 50 58 type = path; 51 59 }; ··· 83 91 wantedBy = [ "multi-user.target" ]; 84 92 85 93 serviceConfig = { 86 - ExecStart = "${pkgs.collectd}/sbin/collectd -C ${conf} -P ${cfg.dataDir}/collectd.pid"; 94 + ExecStart = "${pkgs.collectd}/sbin/collectd -C ${conf} -P ${cfg.pidFile}"; 87 95 Type = "forking"; 88 - PIDFile = "${cfg.dataDir}/collectd.pid"; 96 + PIDFile = cfg.pidFile; 89 97 User = optional (cfg.user!="root") cfg.user; 90 98 PermissionsStartOnly = true; 91 99 }; 92 100 93 101 preStart = '' 94 102 mkdir -m 0700 -p ${cfg.dataDir} 95 - if [ "$(id -u)" = 0 ]; then chown -R ${cfg.user} ${cfg.dataDir}; fi 103 + install -D /dev/null ${cfg.pidFile} 104 + if [ "$(id -u)" = 0 ]; then 105 + chown -R ${cfg.user} ${cfg.dataDir}; 106 + chown ${cfg.user} ${cfg.pidFile} 107 + fi 96 108 ''; 97 109 }; 98 110