Best way to reboot from cli?

sfatula

Guru
Joined
Jul 5, 2022
Messages
608
It appears this command:
Code:
/usr/bin/midclt call system.reboot
reboots immediately and doesn't go through the same shutdown that the gui would, i.e., doesn't stop VMs, etc.

Is there another command I can enter in a script to properly reboot the machine with all the usual stuff taken care of?
 

sfatula

Guru
Joined
Jul 5, 2022
Messages
608
Forgot about cli. Will try this later, but with -c so can be in a script. Thanks!
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
You can also set a delay in the API reboot: midclt call system.reboot '{ "delay": <seconds to delay> }'. This returns a job ID as an integer. To cancel the job, run midclt call core.job_abort <job ID>.
 

sfatula

Guru
Joined
Jul 5, 2022
Messages
608
You can also set a delay in the API reboot: midclt call system.reboot '{ "delay": <seconds to delay> }'. This returns a job ID as an integer. To cancel the job, run midclt call core.job_abort <job ID>.
Yeah, I saw that but that then depends on approximate times to wait. I suppose one could wait 10 minutes to be safe but I really just want a normal shutdown process, just like I clicked it in the gui. But thanks for pointing that out.
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
The UI, CLI menu, and API calls all use the same system backend to shutdown, and should stop VMs, etc.
 

sfatula

Guru
Joined
Jul 5, 2022
Messages
608
The UI, CLI menu, and API calls all use the same system backend to shutdown, and should stop VMs, etc.
That's what I expected to happen, unfortunately, typed the midclt command and it reboot very very quickly (not very many seconds, was shorter than a gui menu reboot!). VMs were not stopped, and showed as much when it rebooted and they finally came up (things in the VM logs showed was not stopped, came back up with messages, etc.). The notifications section of truenas showed (AFTER the reboot) that vms were still being stopped. It stayed that way for hours, only another reboot made it go away.

Note this comment as well: https://www.truenas.com/community/threads/reboot-cron-job.90052/post-623316

Says immediately with a seemingly dire warning, that is exactly what happened. Thus my question. Maybe they *should* do the same thing, but they do not. Maybe it's a bug even but the comment was from a while back, 1.5 years ago. Of course the comment is freenas, not necessarily the same, but that is in fact what it did.
 
Last edited:

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
That's what I expected to happen, unfortunately, typed the midclt command and it reboot very very quickly (not very many seconds, was shorter than a gui menu reboot!). VMs were not stopped, and showed as much when it rebooted and they finally came up (things in the VM logs showed was not stopped, came back up with messages, etc.). The notifications section of truenas showed (AFTER the reboot) that vms were still being stopped. It stayed that way for hours, only another reboot made it go away.

Note this comment as well: https://www.truenas.com/community/threads/reboot-cron-job.90052/post-623316

Says immediately with a seemingly dire warning, that is exactly what happened. Thus my question. Maybe they *should* do the same thing, but they do not. Maybe it's a bug even but the comment was from a while back, 1.5 years ago. Of course the comment is freenas, not necessarily the same, but that is in fact what it did.

Please submit a bug report then, as this isn't the expected behavior.
 

sfatula

Guru
Joined
Jul 5, 2022
Messages
608
Yeah, when I get a chance, I will make a VM that is expendable and takes a little bit for a proper shutdown and leave it started while everything else is stopped, watch the console, and do the command again to verify. I don't know if it's intentional or not, but, it sounds like it is not. But really, I should do the same for the gui "power" button too.
 
Top