My Ubuntu 22.04 virtual machine has been constantly turning off (crashing?) the VNC server. This is the VNC server that is built-in under Settings -> Sharing -> Remote Desktop -> Enable Legacy VNC Protocol.
One way to restart the VNC server is to uncheck the box, then re-check the box.
However, since that has to be done with a GUI, it is really annoying.
So, here is the script that will stop and then restart the VNC server:
#!/bin/env bash
grdctl vnc disable
sleep 5
grdctl vnc enable
Using this script, once your VNC server crashes, you can ssh into the machine, run the script from the command line, and then re-establish your VNC session.
Another tip: be very careful when closing the “Remote Desktop” dialog, because the “X” to close that dialog is right over the red sliding “Sharing” on/off control. Be careful that you don’t accidentally click again, which will disable all Sharing when closing the “Remote Desktop” dialog.