rancher-desktop
rancher-desktop copied to clipboard
Try to terminate Lima instances gracefully first
It seems like we stop the VM using limactl stop -f
, which is killing the qemu
process right away instead of trying to send a shutdown
command first. That means any data not yet committed to disk may be lost.
We should try limactl stop
first, and only if that command either returns an error, or does not return within a reasonable amount of time (30s ?) should we forcibly kill the VM.
I think the problem is in my /etc/periodic/daily/110.clean-tmps
script:
…
find -dx . -fstype local -type f $args -delete $print
find -dx . -fstype local ! -name . -type d $dargs -delete $print
-type f
doesn't include sockets, so they aren't deleted, and then the containing directories aren't deleted.
Workaround-fixed by adding this line after the -type f
line:
find -dx . -fstype local -type s $args -delete $print
But I still don't object to deleting this directory after we do a force-quit.
I think the proper fix for the lima-psl-*
files would be for Lima to delete the even on a forced delete.
This is a separate issue from us needing to do a graceful shutdown (and running sync
first?).
+1
I've created https://github.com/lima-vm/lima/issues/1117 to track the Lima-related work.
We do attempt to stop the VM gracefully: https://github.com/rancher-sandbox/rancher-desktop/blob/5ed9c20e1371eb9e2c9b12b001e76a7a9a24d82d/src/backend/lima.ts#L1780
We also force stop the VM on process exit, but the normal code flow for that is only after the graceful exit has been attempted (when you see the thing about stopping services): https://github.com/rancher-sandbox/rancher-desktop/blob/5ed9c20e1371eb9e2c9b12b001e76a7a9a24d82d/src/backend/lima.ts#L230-L233
Note that we added the force stop because we were seeing Lima getting stuck and not stopping correctly when we attempt it.
Interesting. I often see hard exits (the app exists within 2 seconds of pressing ⌘Q when a settings change has not been fully applied yet, so I think there are some logic flaws in there.
Just right now I did a ⌘Q exit, which just closed the app window and removed the app from the dock. When I clicked "Preferences" from the tray icon, I got the app window back (and an empty! Preferences window). When I exited the app again, the tray icon was gone as well, but qemu was still running. So in this case Lima wasn't stopped at all, even though the app is gone.
Restarting it now somewhat works, but it doesn't start Kubernetes even though it is configured in the Preferences.
So all this may be a different issue, but shutting down RD is not really robust yet.