[HOWTO] start and stop VM with your NAS.

Just about everything is virtual these days. Topics relating to virutalization go here.

Moderator: Lillian.W@AST

sksbir
Posts: 395
youtube meble na wymiar Warszawa
Joined: Tue Aug 25, 2015 9:23 pm

Re: [HOWTO] start and stop VM with your NAS.

Post by sksbir »

docb wrote:It works like a charm. I probably would have worked from the start if I did not try to run it from shell first :?
Is there a possibility to run your script before/after the NAS goes to standby? Right now I have massive problems with my VM after a NAS wake up on lan from standby - I always need to rebot the VM after that. So it would be better just to shut it down / restart when the NAS goes to standy / wakes up.
I think no : If NAS is going to standby, it's because there is no activity, and you request it to have some activity ( freeze or stop VM ) because it have no activity ? 8-)
imho, a NAS who hosts VM should never standby.
docb
Posts: 30
Joined: Sat Sep 09, 2017 1:34 am

Re: [HOWTO] start and stop VM with your NAS.

Post by docb »

Well I often don't really need the nas running when I am on duty. And to save power that would be a nice thing. Bit maybe I just turn it off then, cause your wonderful script works then ;-) By the way, do you know a way to shut it down remotely from another server by script. I just can imagine to open a ssh via the script and pass the credentials which would really not be a safe way
sksbir
Posts: 395
Joined: Tue Aug 25, 2015 9:23 pm

Re: [HOWTO] start and stop VM with your NAS.

Post by sksbir »

docb wrote:Well I often don't really need the nas running when I am on duty. And to save power that would be a nice thing. Bit maybe I just turn it off then, cause your wonderful script works then ;-) By the way, do you know a way to shut it down remotely from another server by script. I just can imagine to open a ssh via the script and pass the credentials which would really not be a safe way
Yes it's a safe way if you don't pass the credential but use key based authentication.
for example : https://www.digitalocean.com/community/ ... nux-server

With this solution, you can remotely invoke a local shell which will freeze or shutdown your WM, take care that they are no more active, and shutdown down the NAS after that.
Maybe remotely brings your NAS to sleep is still working ( take a look at the end of this topic )
docb
Posts: 30
Joined: Sat Sep 09, 2017 1:34 am

Re: [HOWTO] start and stop VM with your NAS.

Post by docb »

Perfect - it works like a charm! Thany you so much for your help!
KPOTOC
Posts: 1
Joined: Mon Apr 24, 2017 12:20 am

Re: [HOWTO] start and stop VM with your NAS.

Post by KPOTOC »

Спасибо))) Работает))) Нужно внимательно все сделать по первому посту!
sksbir
Posts: 395
Joined: Tue Aug 25, 2015 9:23 pm

Re: [HOWTO] start and stop VM with your NAS.

Post by sksbir »

in english please.
Tanzpol
Posts: 1
Joined: Thu Mar 04, 2021 9:01 pm

Re: [HOWTO] start and stop VM with your NAS.

Post by Tanzpol »

Hello!!!

Is this "HowTo" steel good? Now ADM 3.5.4.RE11. And everything was done, like in first post, but VM doesn`t start, is it possible to look for some kind of logs? I don`t know where can I find problems %)
wolvverine
Posts: 26
Joined: Tue Dec 12, 2017 5:36 pm

Re: [HOWTO] start and stop VM with your NAS.

Post by wolvverine »

Add autostart vm after reboot virtual box
Ticket 40684 22 September 2021 08:22 AM

Please add autostart for VMs after reboot.

in phpvirtualbox:

Code: Select all

/* Enable startup / shutdown configuration.
* This only works in linux and you must add the vboxinit file to
* your startup scripts list.
*/
var $startStopConfig = true;
But add proper vboxinit file to startup scripts.

/volume1/Web/virtualbox/vboxinit - example for init file.

in /usr/local/AppCentral/virtualbox/CONTROL/start-stop.sh
add this:

start()
{
# Get all autostart machines
MACHINES=$($su_command "VBoxManage list vms | awk '{ print \$NF }' | sed -e 's/[{}]//g'")
for UUID in $MACHINES; do
STARTUP=$($su_command "VBoxManage getextradata $UUID 'pvbx/startupMode'" | awk '{ print $NF }')
if [ "${STARTUP}" == "auto" ]; then
VMNAME=$($su_command "VBoxManage showvminfo $UUID | sed -n '0,/^Name:/s/^Name:[ \t]*//p'")
echo "$0: starting machine ${VMNAME} ..."
$su_command "VBoxManage startvm $UUID --type headless" >>/var/log/vb.log
fi
done
}

stop()
{
# vms are saved, instead of stopped.
MACHINES=$($su_command "VBoxManage list runningvms | awk '{ print \$NF }' | sed -e 's/[{}]//g'")
for UUID in $MACHINES; do
VMNAME=$($su_command "VBoxManage showvminfo $UUID | sed -n '0,/^Name:/s/^Name:[ \t]*//p'")
echo "$0: saving machine ${VMNAME} state ..."
$su_command "VBoxManage controlvm $UUID savestate" >>/var/log/vb.log
done

}
Mikebos
Posts: 1
Joined: Fri Feb 11, 2022 3:17 am

Re: [HOWTO] start and stop VM with your NAS.

Post by Mikebos »

Can I use this VM auto start/stop script with most current ADM 4.0.3 or file structures changes would not allow for that ?

Thanks !
noiden
Posts: 4
Joined: Wed Feb 16, 2022 4:59 am

Re: [HOWTO] start and stop VM with your NAS.

Post by noiden »

wolvverine wrote:in /usr/local/AppCentral/virtualbox/CONTROL/start-stop.sh
add this:
I don't get this to work. I have added script in the bottom of the /usr/local/AppCentral/virtualbox/CONTROL/start-stop.sh but no autostart of VM's.

Anyone knows a solutions for this?
Post Reply

Return to “Virtualization”