Page 1 of 1
Start script for all VMs in /etc/init.d ?
Posted: 31. May 2008, 19:27
by rowi
Dear all,
since every guy should have the same problem like me, I'd like to ask if there is a start script which starts all my virtual machines when the server comes up and stops them when the server goes down.
I think of a script like /etc/init.d/vboxdrv but one for my VMs.
best regards
Rolf
Posted: 31. May 2008, 19:55
by Sasquatch
Should be fairly simple. All you have to do is catch the parameter (start, stop) and put that in cases or if statements, along the proper parameters for the vboxmanage command. Like '/etc/init.d/vm1 start', would run 'vboxmanage startvm vm1' and stop would send 'vboxmanage control vm vm1 savestate'.
Posted: 31. May 2008, 20:20
by rowi
Thank you for replying. I'd like to start every virtual machine I have in one script, so I don't need to use another script when adding (or removing) a virtual machine. Unfortunately VBoxManage list runningvms doesn't give me a feedback of the names of the running vms. Beside this, I would like to do something like that:
Code: Select all
#! /bin/sh
# Q&D script for starting/stopping vms
start()
{
VBoxManage startvm Debby -type vrdp
VBoxManage startvm Winnie -type vrdp
}
stop()
{
VBoxManage controlvm Debby savestate
VBoxManage controlvm Winnie savestate
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
I've seen that the vms are obviously already stopped by /etc/init.d/vboxdrv in stop mode (calling stop_vms) when shutting down, so there may be no need to stop them in an own script.
The script above could be enhanced by looking for the available machines and start them all. The I'd be happy

. But I don't know how to get the names "Debby" and "Winnie" out of a vboxmanage-command (or from whatever).
If I stop the vms I can connect to them anyway. Is this ok?
best regards
Rolf
Posted: 1. Jun 2008, 14:13
by TerryE
do an xargs on `VBoxManage list vms | egrep ^Name:| cut --characters=18-` or ditto ... runningvms ...
Posted: 1. Jun 2008, 15:02
by JshWright
VBoxManage list runningvms returns the UUIDs of the VMs, which can be used in place of the name for any of the VBox command line tools.
Additionally, you might want to look at using VBoxHeadless rather than VBoxManage -type....
Posted: 6. Jun 2008, 07:47
by thomasjohansen
when running a script like this:
Code: Select all
#!/bin/sh
echo "***setting up network for virtualbox***"
sudo tunctl -t tap1 -u thomas
sudo tunctl -t tap2 -u thomas
sudo brctl addbr br0
sudo ifconfig eth0 0.0.0.0 promisc
sudo brctl addif br0 eth0
sudo ifconfig br0 10.192.67.47 netmask 255.255.255.0
sudo route add default gw 10.192.67.1 br0
sudo brctl addif br0 tap1
sudo brctl addif br0 tap2
sudo ifconfig tap1 up
sudo ifconfig tap2 up
echo "***done setting up network for virtualbox***"
echo "***starting virtualbox VM-mailserver & VM-oipserver"
VBoxManage startvm Mailserver -type vrdp
VBoxManage startvm oipserver -type vrdp
echo "***done starting virtualbox VM-mailserver & VM-oipserver"
it will only start one of the VM's. It cant handle 2 VBoxManage commands after each other because its not finish with the first before it starts the next one.
how to work around this porblem?
Posted: 6. Jun 2008, 10:14
by Sasquatch
Add a sleep for it? Time how long it takes for the command to finish, and set that for the sleep timer plus some extra time in case your system is a bit slower.
Posted: 6. Jun 2008, 10:46
by TerryE
How about:
Code: Select all
...
VBoxManage startvm Mailserver -type vrdp &
VBoxManage startvm oipserver -type vrdp
...
That is put the first startvm into the bg. Though thinking about it, I'd add
& to both startvm's so that the script completes after starting both machines and does not stall the init.d script until the VMs close.
Posted: 6. Jun 2008, 11:58
by Sasquatch
Then I would actually change it to this:
Code: Select all
VBoxManage startvm Mailserver -type vrdp && VBoxManage startvm oipserver -type vrdp
With that line, the second command is executed when the first one is done. I just realized it. I used a similar method for my networking config. I had to bring some interfaces down and up again, so I added them all on one line and it did what it supposed to do. You might be able to do that with your network config too.
I do wonder one thing. Why do you put your eth0 into promisc mode? I don't do it (or it's set automatically) and it runs just fine with Host Interface.
Great worked with &&
Posted: 6. Jun 2008, 13:22
by thomasjohansen
Thx, it worked by adding two && after the first VBoxManage command.
About my networksettings:
I have used alot of time figuring out how to make HIF working, and followed tons of guides, and the one which worked for me was one from the ubuntuforum where it suggested "promisc", so im just repeating what it says.
So for now im keeping it like that, maybe I'll change it when I get a little better with ubuntu in generel. (still a newbie)
Posted: 6. Jun 2008, 13:31
by Sasquatch
I'm pretty green myself, but using the Manual way (that is use VBoxAddIF), I had no problems at all. It works like a charm, no need to change anything, only listed 'bridge_ports lan vbox0 vbox1' in my interfaces file at the brdg interface config.