VM does not autostart with array


Recommended Posts

1 hour ago, johnnie.black said:

IIRC autostart currently only works after first array start, like after a reboot.

Meaning that bringing the array down manually and back up it does not start ? im not sure why i remember it doing things that way. and there is no plugin i can run to do achieve this ?

Link to comment
  • 6 months later...

Hello, do not know if you have fixed your issue. I couldn't find an answer why my vm would not autostart after a windows update.  So I created a script that runs every hour. It is kicked off with user scripts.

 

Here is the script:

 

#!/bin/bash
if [ ! -f "/tmp/vm.txt" ]; then rm /tmp/vm.txt ; fi
virsh list --state-running > /tmp/vm.txt
if grep -q "running" /tmp/vm.txt; then exit
else
virsh start  "Windows Server 2016"
fi

 

I only have one VM but you can replace grep "running" with VM name instead if you multiple vms

 

Hope this helps

Edited by ximian
Link to comment
6 hours ago, ximian said:

Hello, do not know if you have fixed your issue. I couldn't find an answer why my vm would not autostart after a windows update.  So I created a script that runs every hour. It is kicked off with user scripts.

 

Here is the script:

 

#!/bin/bash
if [ ! -f "/tmp/vm.txt" ]; then rm /tmp/vm.txt ; fi
virsh list --state-running > /tmp/vm.txt
if grep -q "running" /tmp/vm.txt; then exit
else
virsh start  "Windows Server 2016"
fi

 

I only have one VM but you can replace grep "running" with VM name instead if you multiple vms

 

Hope this helps

Hi thanks for replying i would like my pfsense vm to autostart when bring up the array. If i were to use this script would it look like this ?

 

#!/bin/bash
if [ ! -f "/tmp/vm.txt" ]; then rm /tmp/vm.txt ; fi
virsh list --state-running > /tmp/vm.txt
if grep -q "running" /tmp/vm.txt; then exit
else
virsh start  "Pfsense"
fi

Link to comment

Be VERY careful when implementing something like this script.

 

I would add a kill feature of some sort, where the script looks for the existence of an arbitrary file on the flash drive before starting the VM, that way you could disable the auto start for troubleshooting. Blindly force starting a VM on a schedule is a bad idea for multiple reasons.

Link to comment
  • 1 month later...
On 10/23/2020 at 7:17 AM, Sinister said:

Hi thanks for replying i would like my pfsense vm to autostart when bring up the array. If i were to use this script would it look like this ?

 

#!/bin/bash
if [ ! -f "/tmp/vm.txt" ]; then rm /tmp/vm.txt ; fi
virsh list --state-running > /tmp/vm.txt
if grep -q "running" /tmp/vm.txt; then exit
else
virsh start  "Pfsense"
fi

Sinister , if Pfsense is the only running VM yes then the script will work. If you have multiple VMs running you need to do a virsh list --all into the file and then grep that file for the particular VM that you want to see running.

 

https://stackoverflow.com/questions/37453525/how-can-i-check-specific-server-running-or-notusing-virsh-commands-before-i-s

Link to comment
On 10/23/2020 at 10:02 AM, jonathanm said:

Be VERY careful when implementing something like this script.

 

I would add a kill feature of some sort, where the script looks for the existence of an arbitrary file on the flash drive before starting the VM, that way you could disable the auto start for troubleshooting. Blindly force starting a VM on a schedule is a bad idea for multiple reasons.

Hi jonathanm, just an fyi. Not blindly starting the VM.  The virsh list --state-running > /tmp/vm.txt commands checks to see if the VM is running, when it is not running the file is empty if it is is running the running text is found in the file.

Link to comment
8 hours ago, ximian said:

Hi jonathanm, just an fyi. Not blindly starting the VM.  The virsh list --state-running > /tmp/vm.txt commands checks to see if the VM is running, when it is not running the file is empty if it is is running the running text is found in the file.

Checking to see if the VM is already running before issuing the VM start is NOT what I meant. You need some way of keeping the VM from trying to start automatically, for troubleshooting purposes. Consider the case where starting the VM immediately hangs the host, for whatever reason. You would be stuck in a loop of bouncing the host, and attempting to get access to kill the startup script before it initiates the VM and immediately hangs the host.

 

You need an out of some sort to allow you to stop the auto start process cleanly. That conditional check, where something external is evaluated before starting the VM, is what I was referring to when I said not to blindly start the VM. It could be as simple as a script in the VM itself modifying a file on the host when it shuts down properly to signal it's OK to restart when needed. That way if the VM crashes for whatever reason, it's not blindly restarted.

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.