Skip to content

Commit 36e261a

Browse files
SuperSandro2000astro
authored andcommitted
Use supervisord to spawn virtiofsd processes instead of disowning them
1 parent bb0c6d8 commit 36e261a

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

nixos-modules/host/default.nix

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,30 +250,37 @@ in
250250
'';
251251
};
252252

253-
"microvm-virtiofsd@" = rec {
253+
"microvm-virtiofsd@" = let
254+
inherit (pkgs.python3Packages) supervisor;
255+
in rec {
254256
description = "VirtioFS daemons for MicroVM '%i'";
255257
before = [ "microvm@%i.service" ];
256258
after = [ "local-fs.target" ];
257259
partOf = [ "microvm@%i.service" ];
258260
unitConfig.ConditionPathExists = "${stateDir}/%i/current/share/microvm/virtiofs";
259261
restartIfChanged = false;
260262
serviceConfig = {
261-
Type = "forking";
262-
GuessMainPID = "no";
263-
WorkingDirectory = "${stateDir}/%i";
263+
ExecReload = "${lib.getExe' supervisor "supervisorctl"} reload";
264+
KillMode = "process";
265+
LimitNOFILE = 1048576;
266+
PrivateTmp = "yes";
264267
Restart = "always";
265268
RestartSec = "5s";
266269
SyslogIdentifier = "microvm-virtiofsd@%i";
267-
LimitNOFILE = 1048576;
270+
WorkingDirectory = "${stateDir}/%i";
268271
};
269272
path = with pkgs; [ virtiofsd ];
270273
script = ''
274+
echo "[supervisord]
275+
" > /tmp/supervisord.conf
276+
271277
for d in $PWD/current/share/microvm/virtiofs/*; do
272278
SOCKET="$(realpath "$(cat $d/socket)")"
273279
SOURCE="$(cat $d/source)"
274280
mkdir -p "$SOURCE"
275281
276-
virtiofsd \
282+
echo "[program:virtiofsd-$(basename "$d")]
283+
command=virtiofsd \
277284
--socket-path=$SOCKET \
278285
--socket-group=${config.users.users.microvm.group} \
279286
--shared-dir "$SOURCE" \
@@ -283,11 +290,12 @@ in
283290
${lib.optionalString (config.microvm.virtiofsd.inodeFileHandles != null)
284291
"--inode-file-handles=${config.microvm.virtiofsd.inodeFileHandles}"
285292
} \
286-
${lib.concatStringsSep " " config.microvm.virtiofsd.extraArgs} \
287-
&
288-
# detach from shell, but remain in systemd cgroup
289-
disown
293+
${lib.concatStringsSep " " config.microvm.virtiofsd.extraArgs}
294+
" >> /tmp/supervisord.conf
290295
done
296+
297+
exec ${lib.getExe' supervisor "supervisord"} --nodaemon --user root \
298+
--configuration /tmp/supervisord.conf
291299
'';
292300
};
293301

0 commit comments

Comments
 (0)