mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-01 15:11:25 +00:00
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
This commit is contained in:
parent
dc9f69c260
commit
67340baa9b
@ -166,7 +166,7 @@
|
||||
dnsmasq = 141;
|
||||
uhub = 142;
|
||||
yandexdisk = 143;
|
||||
collectd = 144;
|
||||
#collectd = 144; #unused
|
||||
consul = 145;
|
||||
mailpile = 146;
|
||||
redmine = 147;
|
||||
|
@ -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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user