Skip to content

Commit

Permalink
Use supervisord to spawn virtiofsd processes instead of disowning them
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 authored and astro committed Jul 16, 2024
1 parent bb0c6d8 commit 36e261a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions nixos-modules/host/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -250,30 +250,37 @@ in
'';
};

"microvm-virtiofsd@" = rec {
"microvm-virtiofsd@" = let
inherit (pkgs.python3Packages) supervisor;
in rec {
description = "VirtioFS daemons for MicroVM '%i'";
before = [ "microvm@%i.service" ];
after = [ "local-fs.target" ];
partOf = [ "microvm@%i.service" ];
unitConfig.ConditionPathExists = "${stateDir}/%i/current/share/microvm/virtiofs";
restartIfChanged = false;
serviceConfig = {
Type = "forking";
GuessMainPID = "no";
WorkingDirectory = "${stateDir}/%i";
ExecReload = "${lib.getExe' supervisor "supervisorctl"} reload";
KillMode = "process";
LimitNOFILE = 1048576;
PrivateTmp = "yes";
Restart = "always";
RestartSec = "5s";
SyslogIdentifier = "microvm-virtiofsd@%i";
LimitNOFILE = 1048576;
WorkingDirectory = "${stateDir}/%i";
};
path = with pkgs; [ virtiofsd ];
script = ''
echo "[supervisord]
" > /tmp/supervisord.conf
for d in $PWD/current/share/microvm/virtiofs/*; do
SOCKET="$(realpath "$(cat $d/socket)")"
SOURCE="$(cat $d/source)"
mkdir -p "$SOURCE"
virtiofsd \
echo "[program:virtiofsd-$(basename "$d")]
command=virtiofsd \
--socket-path=$SOCKET \
--socket-group=${config.users.users.microvm.group} \
--shared-dir "$SOURCE" \
Expand All @@ -283,11 +290,12 @@ in
${lib.optionalString (config.microvm.virtiofsd.inodeFileHandles != null)
"--inode-file-handles=${config.microvm.virtiofsd.inodeFileHandles}"
} \
${lib.concatStringsSep " " config.microvm.virtiofsd.extraArgs} \
&
# detach from shell, but remain in systemd cgroup
disown
${lib.concatStringsSep " " config.microvm.virtiofsd.extraArgs}
" >> /tmp/supervisord.conf
done
exec ${lib.getExe' supervisor "supervisord"} --nodaemon --user root \
--configuration /tmp/supervisord.conf
'';
};

Expand Down

0 comments on commit 36e261a

Please sign in to comment.