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

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