Boot order/priority for VMs and Dockers


Recommended Posts

Hello guys,

 

I've setup a few VMs and dockers that need internet to run correctly, however my router is actually another VM with pfSense. When I reboot unRaid I get a mess of errors because internet is not ready yet.

 

What I wanted to do is to start the VMs and dockers only when my pfSense VM is ready (or maybe just after X seconds after the array starts). Any ideas on how I can do this?

 

Thanks!

Link to comment

I have the same scenario, here's how I handle it.

pfsense VM set to autostart

user scripts at array start kicks off pfsense monitor script

pfsense monitor script waits until successful ping of internal gateway, signifying pfsense is online, then runs additional VMs using virsh start vmname

unraid docker delays stagger starts with a docker that doesn't need internet with a 2 minute delay, which is normally plenty of time for pfsense to get rolling. Other dockers are set for many seconds delay, in a logical order.

 

If I couldn't rely on a quick connect to the internet, I'd add the dockers to my pfsense monitor script and remove them from auto start. As it is right now, I've had no issues with things firing off correctly.

 

Then again, I hardly ever restart my server, it's generally up for several months at a time without restart.

  • Upvote 2
Link to comment
12 hours ago, BRiT said:

I think the built-in/plugin functionality allows to control start order of dockers or vms separately, but no order dependency between those 2 groups.

 

Anything more and you'd have to set dockers not to auto-start and use a custom user script to test for vm running and if so then start your list of dockers.

Thanks for your reply. I've totally missed that, not sure where is it but will try to find it!

 

9 hours ago, jonathanm said:

I have the same scenario, here's how I handle it.

pfsense VM set to autostart

user scripts at array start kicks off pfsense monitor script

pfsense monitor script waits until successful ping of internal gateway, signifying pfsense is online, then runs additional VMs using virsh start vmname

unraid docker delays stagger starts with a docker that doesn't need internet with a 2 minute delay, which is normally plenty of time for pfsense to get rolling. Other dockers are set for many seconds delay, in a logical order.

 

If I couldn't rely on a quick connect to the internet, I'd add the dockers to my pfsense monitor script and remove them from auto start. As it is right now, I've had no issues with things firing off correctly.

 

Then again, I hardly ever restart my server, it's generally up for several months at a time without restart.

Thanks! That sounds exactly like I want to do. Do you have the scripts handy? I might be able to implement them :)

Link to comment
1 hour ago, bluepr0 said:

Do you have the scripts handy?

Set to "At startup of array" in user scripts

#!/bin/bash
echo "/boot/config/plugins/user.scripts/scripts/StartVMs/script" | at now

Named StartVMs in user scripts

#!/bin/bash
printf "%s" "waiting for pfSense ..."
# Change IP to match an address controlled by pfSense.
# I recommend pfSense internal gateway or some address guaranteed to be up when pfSense is finished loading.
# I don't use external IP's because I want my internal network and appliances to be fully available
# whether the internet is actually connected or not.
while ! ping -c 1 -n -w 1 192.168.1.1 &> /dev/null
do
    printf "%c" "."
done
printf "\n%s\n"  "pfSense is back online"
virsh start VMName1
# Insert optional delay to stagger VM starts
#sleep 30
virsh start VMName2

 

  • Thanks 2
  • Upvote 1
Link to comment
44 minutes ago, jonathanm said:

Set to "At startup of array" in user scripts


#!/bin/bash
echo "/boot/config/plugins/user.scripts/scripts/StartVMs/script" | at now

Named StartVMs in user scripts


#!/bin/bash
printf "%s" "waiting for pfSense ..."
# Change IP to match an address controlled by pfSense.
# I recommend pfSense internal gateway or some address guaranteed to be up when pfSense is finished loading.
# I don't use external IP's because I want my internal network and appliances to be fully available
# whether the internet is actually connected or not.
while ! ping -c 1 -n -w 1 192.168.1.1 &> /dev/null
do
    printf "%c" "."
done
printf "\n%s\n"  "pfSense is back online"
virsh start VMName1
# Insert optional delay to stagger VM starts
#sleep 30
virsh start VMName2

 

Awesome! will give it a try. Thanks a lot!

 

How do you handle docker boot and delay? I've checked docker preferences but couldn't find anything related. Will try to find something on the unRaid wiki 🤔

Link to comment
1 hour ago, bluepr0 said:

How do you handle docker boot and delay? I've checked docker preferences but couldn't find anything related. Will try to find something on the unRaid wiki 🤔

If I remember correctly you need to have the array stopped; go to the Dockers page; and then turn on Advanced view.    You should then be able to order docker startups and set delays

Link to comment
9 minutes ago, itimpi said:

If I remember correctly you need to have the array stopped; go to the Dockers page; and then turn on Advanced view.    You should then be able to order docker startups and set delays

Nope, it's done with array started. The key is advanced view, and understanding that the delay is seconds to wait AFTER starting that specific docker. I actually want delay BEFORE starting some dockers, so I compensate by putting a docker that doesn't need network to autostart at the top of the list, and set a significant delay after that one.

 

Start order is literally top to bottom of the items with autostart set to yes, so drag the dockers into the order you need. I had some issues with delay times not saving, so be sure to go back to the page and check your work to make sure everything is as you expected. When you add a docker it will likely screw up your order and delays, so be sure to verify periodically.

  • Upvote 1
Link to comment
2 hours ago, jonathanm said:

Nope, it's done with array started. The key is advanced view, and understanding that the delay is seconds to wait AFTER starting that specific docker. I actually want delay BEFORE starting some dockers, so I compensate by putting a docker that doesn't need network to autostart at the top of the list, and set a significant delay after that one.

 

Start order is literally top to bottom of the items with autostart set to yes, so drag the dockers into the order you need. I had some issues with delay times not saving, so be sure to go back to the page and check your work to make sure everything is as you expected. When you add a docker it will likely screw up your order and delays, so be sure to verify periodically.

Gotcha, thanks!

Link to comment
  • 2 weeks later...
On 3/5/2019 at 2:23 PM, jonathanm said:

Set to "At startup of array" in user scripts


#!/bin/bash
echo "/boot/config/plugins/user.scripts/scripts/StartVMs/script" | at now

Named StartVMs in user scripts


#!/bin/bash
printf "%s" "waiting for pfSense ..."
# Change IP to match an address controlled by pfSense.
# I recommend pfSense internal gateway or some address guaranteed to be up when pfSense is finished loading.
# I don't use external IP's because I want my internal network and appliances to be fully available
# whether the internet is actually connected or not.
while ! ping -c 1 -n -w 1 192.168.1.1 &> /dev/null
do
    printf "%c" "."
done
printf "\n%s\n"  "pfSense is back online"
virsh start VMName1
# Insert optional delay to stagger VM starts
#sleep 30
virsh start VMName2

 

Hello! I've tried to setup today this but it seems the array never starts, it get stuck in "Mounting drives". If I remove the script then it starts correctly. I'm running on 6.7-rc5... maybe that's the problem? 🤔

Link to comment
1 hour ago, bluepr0 said:

Hello! I've tried to setup today this but it seems the array never starts, it get stuck in "Mounting drives". If I remove the script then it starts correctly. I'm running on 6.7-rc5... maybe that's the problem? 🤔

Nope. Your problem is it's not just one script. It's 2 scripts. The top script is set to "At startup of array", the bottom script isn't set to auto start, it's called by the first script. There is a reason I posted it like I did. Name the first one whatever you want, and set it to auto start. The second script MUST be named StartVMs, exactly, and not auto started.

Link to comment
58 minutes ago, jonathanm said:

Nope. Your problem is it's not just one script. It's 2 scripts. The top script is set to "At startup of array", the bottom script isn't set to auto start, it's called by the first script. There is a reason I posted it like I did. Name the first one whatever you want, and set it to auto start. The second script MUST be named StartVMs, exactly, and not auto started.

oh damn, I thought it was just one. Sorry! will try again. 

 

Thanks!

Link to comment

Just tried it but still not working.

 

I'm making sure that from the server I can ping the pfSense machine and it works fine. So this command "ping -c 1 -n -w 1 10.0.1.1" is working.

 

I'm also seeing the first script (I called it VMDelay) on the logs

Mar 20 13:16:03 xserver root: Delaying execution of fix common problems scan for 10 minutes
Mar 20 13:16:03 xserver emhttpd: /usr/local/emhttp/plugins/user.scripts/startBackground.php "/tmp/user.scripts/tmpScripts/VMDelay/script" > /dev/null 2>&1
Mar 20 13:16:03 xserver emhttpd: Starting services...
Mar 20 13:16:03 xserver emhttpd: shcmd (55): /etc/rc.d/rc.samba restart

But after pfSense is back online the other script is not triggering. However if I run it manually from the User Script panel by hitting the "Run Script" button then it turns on my other VMs.

 

I'm probably doing something wrong but not sure how to debug the mistake 🤔

Screenshot 2019-03-20 at 13.19.02.png

Screenshot 2019-03-20 at 13.23.50.png

Edited by bluepr0
Link to comment
21 minutes ago, jonathanm said:

Check to see if that is exactly the name of your StartVMs script. I can't check mine right now, but try navigating to that path and see if the script exists there.

Seems like it's there indeed.

 

 

Screenshot 2019-03-20 at 13.48.10.png

Edited by bluepr0
Link to comment
40 minutes ago, jonathanm said:

That output looks correct, did it kick off the StartVMs script?

Nope, if I run the VMDelay script it runs fine but it doesn't fire the other script it seems, at least the VMs are not getting started. If I run manually StartVMs they do get started so I would guess it's not a problem of the script itself.

 

I did copy and paste the script on Atom to modify and then paste it on the script file on unRAID

 

However here's the text as well

 

#!/bin/bash
printf "%s" "waiting for pfSense ..."
# Change IP to match an address controlled by pfSense.
# I recommend pfSense internal gateway or some address guaranteed to be up when pfSense is finished loading.
# I don't use external IP's because I want my internal network and appliances to be fully available
# whether the internet is actually connected or not.
while ! ping -c 1 -n -w 1 10.0.1.1 &> /dev/null
do
    printf "%c" "."
done
printf "\n%s\n"  "pfSense is back online"
virsh start Hassio
# Insert optional delay to stagger VM starts
sleep 1
virsh start Windows10

And the other one

#!/bin/bash
echo "/boot/config/plugins/user.scripts/scripts/StartVMs/script" | at now

Thanks so much for your help ❤️

Link to comment
Just now, jonathanm said:

What happens if you enter just the second line of the short script at the console command prompt?

echo "/boot/config/plugins/user.scripts/scripts/StartVMs/script" | at now

Does it fire the StartVMs script file?

Nope, I get this output but the VMs stay off

root@xserver:~# echo "/boot/config/plugins/user.scripts/scripts/StartVMs/script" | at now
warning: commands will be executed using /bin/sh
job 8 at Wed Mar 20 15:43:00 2019
root@xserver:~# 

 

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.