VM Auto Start ??

StarTrek133

Contributor
Joined
Sep 5, 2022
Messages
112
Hey Everyone,

Quick question .. is there a way to auto start if your VM is not in a "running state" .. I have this issue where my VM of windows 10 keeps turning off for no reason at all .. I cant find anything in the log files of windows 10 about crashing or shutting down .. and I don't know enough about TrueNas Core to find any log files with errors ..

So I know in windows you can set a task to restart a "service" but can't seem to find that in TrueNas Core ..

So thought I would ask .. Thanks for the help ..
 

artlessknave

Wizard
Joined
Oct 29, 2016
Messages
1,506
you can set it to autostart on boot in the GUI, but to constantly check it and start it would probably need a cron script.

something like
iohyve start VMname, which should just do nothing if its already started. and then set a cron job in tasks, maybe every hour.

ASUS TUF Gaming is........not really a TrueNAS platform. it's possible you are getting invisible RAM errors. you might want to memtest your system.

if it's not that, you might want to rebuild the VM, or use another OS instead of windows.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
something like
iohyve start VMname, which should just do nothing if its already started. and then set a cron job in tasks, maybe every hour.
It would probably be much better to work with the middleware to do that and ensure the state of the VM is known by the GUI/middleware at all times.

Something like this:

midclt call vm.query | jq '[.[] | .id, .name, .status.state]'

Then (once you know the ID of your VM... let's say 18 for the example)

midclt call vm.query | jq '[.[] | select(.id == 18) | .name, .status.state]'

Then test the results against "stopped"

midclt call vm.query | jq '[.[] | select(.id == 18) | .name, .status.state]' | grep STOPPED

then:

midclt call vm.start 18

Put it all together for a single command in a cron job:
midclt call vm.query | jq '[.[] | select(.id == 18) | .name, .status.state]' | grep STOPPED && midclt call vm.start 18
 

StarTrek133

Contributor
Joined
Sep 5, 2022
Messages
112
Thanks for the advice ..

Yeah my trouble is for no reason that I can find so far .. the VM goes from a Started "State" to off .. and I have log in and turn it back on to get plex and my other media programs working ..

I don't know enough about TrueNas Core to find any log files that would state why it was turned off .. Also when I check the windows vm its like your just starting up .. no pop ups or anything that says this computer was powered off or whatever it is when that happens .. I have also checked the vm with sfc /scannow and chkdsk and both are fine .. so I don't know ..

Here is my vm page ..

Only thing I can think of is maybe the whole system doesn't have enough ram ?
 

Attachments

  • Screenshot 2023-01-08 192051.jpg
    Screenshot 2023-01-08 192051.jpg
    53.1 KB · Views: 129
  • Screenshot 2023-01-08 192406.jpg
    Screenshot 2023-01-08 192406.jpg
    139.9 KB · Views: 134

StarTrek133

Contributor
Joined
Sep 5, 2022
Messages
112
So Sretatta you mean something like this ..
 

Attachments

  • Screenshot 2023-01-08 192741.jpg
    Screenshot 2023-01-08 192741.jpg
    43.4 KB · Views: 132
  • Screenshot 2023-01-08 192721.jpg
    Screenshot 2023-01-08 192721.jpg
    37.6 KB · Views: 119

StarTrek133

Contributor
Joined
Sep 5, 2022
Messages
112
I tired to run it and it errored out .. So I would assume that is ok because its already running .. but here is the log file ..


jq: error: Trek133/0 is not defined at <top-level>, line 1:
[.[] | select(.id == Trek133) | .name, .status.state]
jq: 1 compile error
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
Executed CronTask - midclt call vm.query | jq '[.[] | select(.id == Trek133) | .name, .status.state]' | grep STOPPED && midclt call vm.start Trek133 > /dev/null: jq: error: Trek133/0 is not defined at <top-level>, line 1:
[.[] | select(.id == Trek133) | .name, .status.state]
jq: 1 compile error
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
So Sretatta you mean something like this ..
Well, not quite...

If you read my post you would see I recommend first running a query to see the ID of your VM... (won't be its name, but rather an integer).

You then use that integer (I gave the example of 18 in my post) in the last command to run the task.
 

StarTrek133

Contributor
Joined
Sep 5, 2022
Messages
112
So something like this then ..
 

Attachments

  • Screenshot 2023-01-10 192030.jpg
    Screenshot 2023-01-10 192030.jpg
    42.3 KB · Views: 124
  • Screenshot 2023-01-10 192001.jpg
    Screenshot 2023-01-10 192001.jpg
    78.7 KB · Views: 112

Whattteva

Wizard
Joined
Mar 5, 2013
Messages
1,824
Hey Everyone,

Quick question .. is there a way to auto start if your VM is not in a "running state" .. I have this issue where my VM of windows 10 keeps turning off for no reason at all .. I cant find anything in the log files of windows 10 about crashing or shutting down .. and I don't know enough about TrueNas Core to find any log files with errors ..

So I know in windows you can set a task to restart a "service" but can't seem to find that in TrueNas Core ..

So thought I would ask .. Thanks for the help ..
How much RAM do you have? I have this problem on both Proxmox and TrueNAS CORE back when I ran them on 16 GB machines. The issue stops completely once I upgraded to 32 GB.

If your VM's are shutting off on its own, you should actually attack the root cause of the problem that's making them do so and not trying to hack it through with watchdog kludge. Your VM's aren't supposed to do that.
 

artlessknave

Wizard
Joined
Oct 29, 2016
Messages
1,506

Whattteva

Wizard
Joined
Mar 5, 2013
Messages
1,824

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703

StarTrek133

Contributor
Joined
Sep 5, 2022
Messages
112
How much RAM do you have? I have this problem on both Proxmox and TrueNAS CORE back when I ran them on 16 GB machines. The issue stops completely once I upgraded to 32 GB.

If your VM's are shutting off on its own, you should actually attack the root cause of the problem that's making them do so and not trying to hack it through with watchdog kludge. Your VM's aren't supposed to do that.
Currently I have 24gb in it , but planning on upgrading to 64gb once I get the money to buy the kits ..
 

StarTrek133

Contributor
Joined
Sep 5, 2022
Messages
112
Hey Sretalla ..

I finally got to test it out and it works .. but I think my schedule is not correct .. I want it to run every hour ...
 

Attachments

  • Screenshot 2023-01-21 205300.jpg
    Screenshot 2023-01-21 205300.jpg
    83.4 KB · Views: 127

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
So you meant to select hourly at the top then? (instead of daily)
 

StarTrek133

Contributor
Joined
Sep 5, 2022
Messages
112
Thanks Sretalla .. I got that done so should be all set and hope that when I get more Ram in the furture I can turn the job off and be good ..

I am also going to assume that the error that comes up is because the VM is already running and command just errored out .. and there is nothing to worry about ..


highlight_offcronjob.run85.00%

Status: FAILED
Start Time: 2023-01-22 13:00:00
Finished Time: 2023-01-22 13:00:00

Error: [EFAULT] CronTask "midclt call vm.query | jq '[.[] | select(.id == 1) | .name, .status.state]' | grep STOPPED && midclt call vm.start 1 > /dev/null" exited with 1 (non-zero) exit status.
 
Top