upstart: options for setuid and setgid

as jobs running as different users cannot create their logfile, I moved that to an activationScript

svn path=/nixos/trunk/; revision=32762
This commit is contained in:
Mathijs Kwik 2012-03-04 12:58:06 +00:00
parent 79d4b11aeb
commit dc8ca0ea4a

View File

@ -6,6 +6,11 @@ let
upstart = pkgs.upstart; upstart = pkgs.upstart;
userExists = u:
(u == "") || any (uu: uu.name == u) (attrValues config.users.extraUsers);
groupExists = g:
(g == "") || any (gg: gg.name == g) (attrValues config.users.extraGroups);
# From a job description, generate an Upstart job file. # From a job description, generate an Upstart job file.
makeJob = job: makeJob = job:
@ -95,6 +100,14 @@ let
throw "invalid daemon type `${job.daemonType}'" throw "invalid daemon type `${job.daemonType}'"
)} )}
${optionalString (job.setuid != "") ''
setuid ${job.setuid}
''}
${optionalString (job.setgid != "") ''
setuid ${job.setgid}
''}
${job.extraConfig} ${job.extraConfig}
''; '';
@ -255,6 +268,24 @@ let
''; '';
}; };
setuid = mkOption {
type = types.string;
check = userExists;
default = "";
description = ''
Run the daemon as a different user.
'';
};
setgid = mkOption {
type = types.string;
check = groupExists;
default = "";
description = ''
Run the daemon as a different group.
'';
};
extraConfig = mkOption { extraConfig = mkOption {
type = types.string; type = types.string;
default = ""; default = "";
@ -368,6 +399,13 @@ in
# do status queries. # do status queries.
services.dbus.packages = [ upstart ]; services.dbus.packages = [ upstart ];
system.activationScripts.chownJobLogs = stringAfter ["var"]
(concatMapStrings (job: ''
touch /var/log/upstart/${job.name}
${optionalString (job.setuid != "") "chown ${job.setuid} /var/log/upstart/${job.name}"}
${optionalString (job.setgid != "") "chown :${job.setgid} /var/log/upstart/${job.name}"}
'') (attrValues config.jobs));
}; };
} }