fix: use screen -dmS with Type=forking for console drain service

screen -dmS forks to background (daemon mode), which should work
without a controlling terminal. Type=forking tells systemd to expect
the fork.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Davíð Steinn Geirsson 2026-03-21 20:10:06 +00:00
parent dae577fe0f
commit 43438277d8
3 changed files with 11 additions and 11 deletions

View file

@ -540,7 +540,7 @@ vm-shell --ssh <name> # SSH into VM as user
vm-shell --ssh --root <name> # SSH into VM as root
```
The default serial console mode connects via a `tmux` session. Press `Ctrl+B, D` to detach. No configuration required.
The default serial console mode connects via a `screen` session. Press `Ctrl+A, D` to detach. No configuration required.
SSH mode requires SSH keys configured in per-VM `guestConfig` (see Advanced Configuration). For cloud-hypervisor VMs, `--ssh` automatically connects via a ProxyCommand over the vsock socket — no IP routing required.

View file

@ -1399,8 +1399,8 @@ let
echo " --ssh Use SSH over vsock (requires SSH keys configured)" >&2
echo " --root Connect as root (only with --ssh)" >&2
echo "" >&2
echo "Without --ssh, connects to serial console via tmux." >&2
echo "Detach with Ctrl+B, D" >&2
echo "Without --ssh, connects to serial console via screen." >&2
echo "Detach with Ctrl+A, D" >&2
exit 1
}
@ -1454,13 +1454,13 @@ let
"${vm.name}) exec ${pkgs.openssh}/bin/ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ProxyCommand=${lib.escapeShellArg "${proxyCmd}"} \$USER_NAME@localhost ;;"
)}
else
if ! ${pkgs.tmux}/bin/tmux has-session -t vmsilo-$VM_NAME 2>/dev/null; then
if ! ${pkgs.screen}/bin/screen -ls vmsilo-$VM_NAME >/dev/null 2>&1; then
echo "No console session found for $VM_NAME" >&2
echo "Is the VM running? Use: vm-start $VM_NAME" >&2
exit 1
fi
echo "Detach with Ctrl+B, D"
exec ${pkgs.tmux}/bin/tmux attach -t vmsilo-$VM_NAME
echo "Detach with Ctrl+A, D"
exec ${pkgs.screen}/bin/screen -x vmsilo-$VM_NAME
fi
'';
in

View file

@ -472,7 +472,7 @@ in
) (lib.filter (vm: vm.hypervisor == "crosvm") (lib.attrValues cfg.nixosVms))
++
# Console screen services (one per VM)
# Attaches a tmux session to the console PTY to keep the buffer drained
# Attaches a screen session to the console PTY to keep the buffer drained
map (
vm:
let
@ -488,7 +488,7 @@ in
echo "Timeout waiting for console PTY" >&2
exit 1
fi
exec ${pkgs.tmux}/bin/tmux new-session -s vmsilo-${vm.name} -x 200 -y 50 "cat /run/vmsilo/${vm.name}/console"
${pkgs.screen}/bin/screen -dmS vmsilo-${vm.name} -h 10000 /run/vmsilo/${vm.name}/console
'';
in
lib.nameValuePair "vmsilo-${vm.name}-console-screen" {
@ -499,11 +499,11 @@ in
bindsTo = [ "vmsilo-${vm.name}-vm.service" ];
serviceConfig = {
Type = "simple";
Type = "forking";
User = cfg.user;
ExecStartPre = "-${pkgs.tmux}/bin/tmux kill-session -t vmsilo-${vm.name}";
ExecStartPre = "-${pkgs.screen}/bin/screen -S vmsilo-${vm.name} -X quit";
ExecStart = "${screenScript}";
ExecStopPost = "-${pkgs.tmux}/bin/tmux kill-session -t vmsilo-${vm.name}";
ExecStopPost = "-${pkgs.screen}/bin/screen -S vmsilo-${vm.name} -X quit";
};
}
) (lib.attrValues cfg.nixosVms)