bluepr0 Posted March 4, 2019 Share Posted March 4, 2019 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! Quote Link to comment
JonathanM Posted March 5, 2019 Share Posted March 5, 2019 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. 2 Quote Link to comment
bluepr0 Posted March 5, 2019 Author Share Posted March 5, 2019 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 Quote Link to comment
JonathanM Posted March 5, 2019 Share Posted March 5, 2019 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 2 1 Quote Link to comment
bluepr0 Posted March 5, 2019 Author Share Posted March 5, 2019 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 🤔 Quote Link to comment
itimpi Posted March 5, 2019 Share Posted March 5, 2019 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 Quote Link to comment
JonathanM Posted March 5, 2019 Share Posted March 5, 2019 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. 1 Quote Link to comment
bluepr0 Posted March 5, 2019 Author Share Posted March 5, 2019 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! Quote Link to comment
John_M Posted March 5, 2019 Share Posted March 5, 2019 This is ingenious stuff. I just have a separate box that serves as my router/firewall/DNS/DHCP. Quote Link to comment
bluepr0 Posted March 20, 2019 Author Share Posted March 20, 2019 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? 🤔 Quote Link to comment
JonathanM Posted March 20, 2019 Share Posted March 20, 2019 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. Quote Link to comment
bluepr0 Posted March 20, 2019 Author Share Posted March 20, 2019 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! Quote Link to comment
bluepr0 Posted March 20, 2019 Author Share Posted March 20, 2019 (edited) 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 🤔 Edited March 20, 2019 by bluepr0 Quote Link to comment
JonathanM Posted March 20, 2019 Share Posted March 20, 2019 3 hours ago, bluepr0 said: #!/bin/bash echo "/boot/config/plugins/user.scripts/scripts/StartVMs/script" | at now 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. Quote Link to comment
bluepr0 Posted March 20, 2019 Author Share Posted March 20, 2019 (edited) 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. Edited March 20, 2019 by bluepr0 Quote Link to comment
JonathanM Posted March 20, 2019 Share Posted March 20, 2019 30 minutes ago, bluepr0 said: Seems like it's there indeed. Can't tell from that screenshot. What's inside the StartVMs folder? Quote Link to comment
bluepr0 Posted March 20, 2019 Author Share Posted March 20, 2019 10 minutes ago, jonathanm said: Can't tell from that screenshot. What's inside the StartVMs folder? Sorry, this should do it. Quote Link to comment
JonathanM Posted March 20, 2019 Share Posted March 20, 2019 What's the output if you click "run script" on the VMDelay? Quote Link to comment
bluepr0 Posted March 20, 2019 Author Share Posted March 20, 2019 6 minutes ago, jonathanm said: What's the output if you click "run script" on the VMDelay? This should be it Quote Link to comment
JonathanM Posted March 20, 2019 Share Posted March 20, 2019 That output looks correct, did it kick off the StartVMs script? Quote Link to comment
JonathanM Posted March 20, 2019 Share Posted March 20, 2019 BTW, if you copied and pasted from the forum, it can introduce stray characters. It's best to type this kind of stuff out manually, or paste it into an editor that will show you all the raw characters like notepad++. Quote Link to comment
bluepr0 Posted March 20, 2019 Author Share Posted March 20, 2019 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 ❤️ Quote Link to comment
JonathanM Posted March 20, 2019 Share Posted March 20, 2019 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? Quote Link to comment
bluepr0 Posted March 20, 2019 Author Share Posted March 20, 2019 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 [email protected]:~# 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 [email protected]:~# Quote Link to comment
JonathanM Posted March 20, 2019 Share Posted March 20, 2019 Weird. So if you type just the portion inside the double quotes, what happens? /boot/config/plugins/user.scripts/scripts/StartVMs/script Quote Link to comment
Recommended Posts
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.