Restart VM from CLI?

Joined
Dec 2, 2015
Messages
730
I'm trying out a VM running Ubuntu to get Docker. I've had one instance where the VM locked up, requiring a restart. I'd like to set up some sort of watchdog to automatically restart the VM if it locks up again. shutdown -r now works great inside the VM, if the VM is running, but this is obviously useless if the VM has locked up.

Is there a way to restart a VM via the CLI on TrueNAS Core?
 
Joined
Dec 2, 2015
Messages
730
I'm trying out a VM running Ubuntu to get Docker. I've had one instance where the VM locked up, requiring a restart. I'd like to set up some sort of watchdog to automatically restart the VM if it locks up again. shutdown -r now works great inside the VM, if the VM is running, but this is obviously useless if the VM has locked up.

Is there a way to restart a VM via the CLI on TrueNAS Core?
The surest way to find the info you are looking for is to post a question on a public forum. You'll then find the info yourself within minutes.

It looks like virsh is the tool I need. virsh list lists the running VMs. virsh reboot <VM Name from virsh list> reboots the VM. Now I just need to figure out the best way to check the health of the service I need from outside the VM, so I can use it as the trigger for a script which runs every few minutes via cron. Theoretically, the VM could be running fine, but the service inside the VM could lock up, so I need something more bulletproof than simply pinging the VM.
 
Joined
Jan 20, 2023
Messages
2
I'm trying out a VM running Ubuntu to get Docker. I've had one instance where the VM locked up, requiring a restart. I'd like to set up some sort of watchdog to automatically restart the VM if it locks up again. shutdown -r now works great inside the VM, if the VM is running, but this is obviously useless if the VM has locked up.

Is there a way to restart a VM via the CLI on TrueNAS Core?
Hey Kevin, I passed a pcie resource to a VM incorrectly and the system froze and won’t reboot without crashing. I and rebooting in recovery mode and trying to turn off the “start VM flag automatically” from CLI bc I can’t find where
 
Joined
Dec 2, 2015
Messages
730
Hey Kevin, I passed a pcie resource to a VM incorrectly and the system froze and won’t reboot without crashing. I and rebooting in recovery mode and trying to turn off the “start VM flag automatically” from CLI bc I can’t find where
Sorry, I have not been able to find which file holds that info.

But, you may be able to change the autostart setting with virsh

man virsh suggests that virsh autostart --disable <domain> might do it, where the value of "<domain>" is found from virsh list.
 
Joined
Jan 20, 2023
Messages
2
I tried that but in recovery mode the virtlibd daemon was not running and seems the issue was i could not get it to work due to not being root. i got into the VM xml file and changed the autostart on reboot flag, but then had the next issue. "changes made with CLI doesn't survive reboot".

Long story short i simply reinstalled the boot-pool and upgraded the bootloader to the latest scale and used my last sys config file to setup UI and then reinserted my drives and imported pools. All data is there just have to reconfigure some of shares.

But lesson learned is to make sure the start auto flag on VM is turned off while setting up/testing VM to prevent this end less loop of crashing.
Also to make a periodic sys config save, maybe on an attached usb internal/external to system. And Save Pool Encryption Keys, offline away from the pools.
 
Top