Write daemon log files in the temp dir for processes running without root privileges

This commit is contained in:
Sander van der Burg 2020-11-25 22:14:32 +01:00 committed by Sander van der Burg
parent 5ab68c5b55
commit 3a3865425f
7 changed files with 26 additions and 9 deletions

View File

@ -1052,7 +1052,9 @@ Services that only provide foreground processes are automatically daemonized
with the `daemon` command by these three backends. By default, the `daemon`
command will capture their outputs in log files with a `nixproc-` prefix in
the log directory. On a production system, such a log file could be:
`/var/log/nixproc-myservice.log`.
`/var/log/nixproc-myservice.log` for services that are started as root users
and `/tmp/nixproc-myservice.log` for services that are started as unprivileged
users.
### supervisord

View File

@ -63,7 +63,8 @@ let
pidFile = _pidFile;
user = _user;
outputLogFile = util.autoGenerateDaemonLogFilePath {
inherit name instanceName logDir;
inherit name instanceName logDir tmpDir;
user = _user;
enableDaemonOutputLogging = true;
};
inherit pidFilesDir;

View File

@ -97,7 +97,8 @@ let
};
outputLogFile = util.autoGenerateDaemonLogFilePath {
inherit name instanceName logDir enableDaemonOutputLogging;
inherit name instanceName logDir tmpDir enableDaemonOutputLogging;
user = _user;
};
_command = if commandIsDaemon then command else "daemon";

View File

@ -142,7 +142,8 @@ let
user = _user;
pidFile = _pidFile;
outputLogFile = util.autoGenerateDaemonLogFilePath {
inherit name instanceName logDir enableDaemonOutputLogging;
inherit name instanceName logDir tmpDir enableDaemonOutputLogging;
user = _user;
};
inherit process args pidFilesDir;
};

View File

@ -64,10 +64,14 @@ rec {
* Auto-generates the path to the log file that captures the
* output of a process invoked with the daemon command
*/
autoGenerateDaemonLogFilePath = {name, instanceName, logDir, enableDaemonOutputLogging ? true}:
autoGenerateDaemonLogFilePath = {name, instanceName, logDir, tmpDir, user, enableDaemonOutputLogging ? true}:
if enableDaemonOutputLogging then
if instanceName == null then "${logDir}/nixproc-${name}.log"
else "${logDir}/nixproc-${instanceName}.log"
if instanceName == null then
if user == null then "${logDir}/nixproc-${name}.log"
else "${tmpDir}/nixproc-${name}.log"
else
if user == null then "${logDir}/nixproc-${instanceName}.log"
else "${tmpDir}/nixproc-${instanceName}.log"
else null;
/*

View File

@ -37,10 +37,14 @@ makeTest {
virtualisation.diskSize = 4096;
virtualisation.memorySize = 8192;
dysnomia = {
enable = true;
enableLegacyModules = false;
};
environment.systemPackages = [
tools.common
tools.systemd
pkgs.dysnomia
pkgs.docker
];
};

View File

@ -75,9 +75,13 @@ makeTest {
substitute = false
'';
dysnomia = {
enable = true;
enableLegacyModules = false;
};
environment.systemPackages = [
pkgs.stdenv
pkgs.dysnomia
pkgs.disnix
tools.common
tools.systemd