|
250 | 250 | '';
|
251 | 251 | };
|
252 | 252 |
|
253 |
| - "microvm-virtiofsd@" = rec { |
| 253 | + "microvm-virtiofsd@" = let |
| 254 | + inherit (pkgs.python3Packages) supervisor; |
| 255 | + in rec { |
254 | 256 | description = "VirtioFS daemons for MicroVM '%i'";
|
255 | 257 | before = [ "microvm@%i.service" ];
|
256 | 258 | after = [ "local-fs.target" ];
|
257 | 259 | partOf = [ "microvm@%i.service" ];
|
258 | 260 | unitConfig.ConditionPathExists = "${stateDir}/%i/current/share/microvm/virtiofs";
|
259 | 261 | restartIfChanged = false;
|
260 | 262 | 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"; |
264 | 267 | Restart = "always";
|
265 | 268 | RestartSec = "5s";
|
266 | 269 | SyslogIdentifier = "microvm-virtiofsd@%i";
|
267 |
| - LimitNOFILE = 1048576; |
| 270 | + WorkingDirectory = "${stateDir}/%i"; |
268 | 271 | };
|
269 | 272 | path = with pkgs; [ virtiofsd ];
|
270 | 273 | script = ''
|
| 274 | + echo "[supervisord] |
| 275 | + " > /tmp/supervisord.conf |
| 276 | +
|
271 | 277 | for d in $PWD/current/share/microvm/virtiofs/*; do
|
272 | 278 | SOCKET="$(realpath "$(cat $d/socket)")"
|
273 | 279 | SOURCE="$(cat $d/source)"
|
274 | 280 | mkdir -p "$SOURCE"
|
275 | 281 |
|
276 |
| - virtiofsd \ |
| 282 | + echo "[program:virtiofsd-$(basename "$d")] |
| 283 | + command=virtiofsd \ |
277 | 284 | --socket-path=$SOCKET \
|
278 | 285 | --socket-group=${config.users.users.microvm.group} \
|
279 | 286 | --shared-dir "$SOURCE" \
|
|
283 | 290 | ${lib.optionalString (config.microvm.virtiofsd.inodeFileHandles != null)
|
284 | 291 | "--inode-file-handles=${config.microvm.virtiofsd.inodeFileHandles}"
|
285 | 292 | } \
|
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 |
290 | 295 | done
|
| 296 | +
|
| 297 | + exec ${lib.getExe' supervisor "supervisord"} --nodaemon --user root \ |
| 298 | + --configuration /tmp/supervisord.conf |
291 | 299 | '';
|
292 | 300 | };
|
293 | 301 |
|
|
0 commit comments