You are not logged in.

#1 2008-12-25 03:38:23

skysurfer
Member
From: Greece/Thessaloniki
Registered: 2007-08-10
Posts: 30
Website

Virtualbox daemon

To begin, i am sorry if this is the wrong place for this post smile

I run an Arch linux server and i use Virtualbox-bin in order to host some windows services.

Until now, i have been starting the vm using /etc/rc.local:

/bin/su skysurfer -c "/usr/bin/VBoxHeadless -s winxp -v off"

The last days this has stopped working. Is there a way to make a custom daemon in /etc/rc.d so that i can start the vm as a system service?

I want to do the same for opendchub and other services... I guess the method would be the same.

Thanks in advance smile

Last edited by skysurfer (2008-12-25 03:40:37)


Archlinux rulez tongue

My home server running Arch 24/7:
Intel Atom 330, 2GB RAM, 2TB Disks

Offline

#2 2009-01-11 21:15:33

cipparello
Member
From: Verona, Italy
Registered: 2008-05-19
Posts: 16

Re: Virtualbox daemon

Hi skysurfer,
    I see your post only now... it's quite old and maybe you already have found a solution. Anyway if you like you can try this http://vboxtool.sourceforge.net/ It start/stop the VBox machines during boot/shutdown using VBoxHeadless (so without the needs to install all the X stuff...); I uploaded it on AUR (see http://aur.archlinux.org/packages.php?ID=23086)

If you don't want to use it you can watch at the script on the author's site and use it as a template or inspiration for your solution.

bye

Offline

#3 2009-01-11 21:21:17

RedShift
Member
From: Belgium
Registered: 2004-07-16
Posts: 230

Re: Virtualbox daemon

conf.virtualbox:

# The user which the virtual machines are running
VBOX_USER=glenn
# Machines to start at boot
VBOX_MACHINES=(CentOS)


# Worst case scenario, shutting down will take VBOX_WAIT * VBOX_RETRY seconds.
# At first we send the ACPI powerbutton event, after this we do a poweroff

# Seconds to wait while shutting down
VBOX_WAIT=30

# Number of times to retry sending the ACPI powerbutton event
VBOX_RETRY=5

rc.virtualbox:

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

[ -f /etc/conf.d/virtualbox ]  && . /etc/conf.d/virtualbox

SU="su $VBOX_USER -c"
VBOXMANAGE="VBoxManage -nologo"
VBOXHEADLESS="VBoxHeadless"

# Send the ACPI powerbutton event to the virtual machine
vbox_powerbutton() {
    $SU "$VBOXMANAGE controlvm \"$1\" acpipowerbutton"
}

# Poweroff the machine
vbox_poweroff() {
    $SU "$VBOXMANAGE controlvm \"$1\" poweroff"
}

# Start the virtual machine
vbox_start() {
    $SU "$VBOXHEADLESS -s \"$1\" > /dev/null &"
}

# List all running VMs
vbox_list() {
    $SU "$VBOXMANAGE list runningvms"
}

case "$1" in
    
    start)
        stat_busy "Starting VirtualBox machines"
        for machine in "${VBOX_MACHINES[@]}"; do
            vbox_start $machine
            if [ $? -gt 0 ]; then
                echo "WARNING: FAILED STARTING $machine"
            fi
        done
        add_daemon virtualbox
        stat_done
    ;;
    
    stop)
        stat_busy "Stopping VirtualBox machines"
        tries=0
        while [ $tries -lt $VBOX_RETRY ]; do
            for machine in `vbox_list`; do
                vbox_powerbutton $machine
                sleep $VBOX_WAIT
            done;
            tries=$((tries + 1))
        done
        for machine in `vbox_list`; do
            echo "WARNING: UNCLEAN SHUTDOWN $machine"
            vbox_poweroff $machine
        done
        rm_daemon virtualbox
        stat_done
    ;;
    
    restart)
        $0 stop
        $0 start
    ;;

    *)
    echo "usage: $0 {start|stop|restart}"
    
esac

exit 0

:?

Offline

#4 2009-01-30 11:12:17

skysurfer
Member
From: Greece/Thessaloniki
Registered: 2007-08-10
Posts: 30
Website

Re: Virtualbox daemon

Thanks guys for your answers! I will check them as soon as possible


Archlinux rulez tongue

My home server running Arch 24/7:
Intel Atom 330, 2GB RAM, 2TB Disks

Offline

#5 2009-01-30 23:06:27

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,217
Website

Re: Virtualbox daemon

Nice one RedShift smile

Offline

#6 2011-01-09 17:07:59

Da_Coynul
Member
From: United States of America
Registered: 2010-10-02
Posts: 85

Re: Virtualbox daemon

Sorry to bump an old thread but this is very useful information that deserves to be updated, so here it goes:

If you modify this section of RedShift's script:

# List all running VMs
vbox_list() {
    $SU "$VBOXMANAGE list runningvms"
}

to look like this:

# List all running VMs
vbox_list() {
    $SU "$VBOXMANAGE list runningvms | sed -e 's/^\".*\".*{\(.*\)}/\1/'"
}

You can eliminate errors like this:

ERROR: Could not find a registered machine named '{26f8caca-ddc5-40c0-94d3-2ee29c9e26bb}'
  Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee nsISupports
  Context: "FindMachine (Bstr(a->argv[0]), machine.asOutParam())" at line 570 of file VBoxManage.cpp
  ERROR: Could not find a registered machine named '{093d1dcb-e581-403d-a00d-234972fb5ca5}'
  Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee nsISupports
  Context: "FindMachine (Bstr(a->argv[0]), machine.asOutParam())" at line 570 of file VBoxManage.cpp

See here for more details:

http://virtual-box.de/ticket/4388

Thanks again, RedShift!

Offline

#7 2011-03-04 02:34:06

skysurfer
Member
From: Greece/Thessaloniki
Registered: 2007-08-10
Posts: 30
Website

Re: Virtualbox daemon

I did some modifications to RedShift's script to match my needs. This is it:

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

[ -f /etc/conf.d/virtualbox ]  && . /etc/conf.d/virtualbox

SU="su $VBOX_USER -c"
VBOXMANAGE="VBoxManage --nologo"
VBOXHEADLESS="VBoxHeadless"

vbox_stop() {
    $SU "$VBOXMANAGE controlvm \"$1\" acpipowerbutton"
}

vbox_start() {
    $SU "$VBOXHEADLESS -s \"$1\" -v config > /dev/null &"
}

# List all running VMs
vbox_list() {
    $SU "$VBOXMANAGE list runningvms"
}

case "$1" in
    
    start)
        stat_busy "Starting VirtualBox machines"
        for machine in "${VBOX_MACHINES[@]}"; do
            vbox_start $machine
        done
        add_daemon virtualbox
        stat_done
    ;;
    
    stop)
        stat_busy "Stopping VirtualBox machines"
           for machine in `vbox_list`; do
               vbox_stop $machine
            done;
            sleep 30
        rm_daemon virtualbox
        stat_done
    ;;
    
    restart)
        $0 stop
        $0 start
    ;;

    *)
    echo "usage: $0 {start|stop|restart}"
    
esac

exit 0

When my arch-box boots, only the first of the two virtual machines start. The other one stays powered off.
When i run the script from terminal as root, all virtual machines star normally.

Same thing happens when i add these lines to /etc/rc.local (as suggested in arch wiki):

exec /bin/su -c "VBoxHeadless -s openser -v off" homer >/dev/null 2>&1
exec /bin/su -c "VBoxHeadless -s winserver" homer >/dev/null 2>&1

Only one machine starts (the first).

Any ideas?


Archlinux rulez tongue

My home server running Arch 24/7:
Intel Atom 330, 2GB RAM, 2TB Disks

Offline

#8 2011-05-02 14:26:27

skysurfer
Member
From: Greece/Thessaloniki
Registered: 2007-08-10
Posts: 30
Website

Re: Virtualbox daemon

I think i found the solution. I added a sleep timer after the command "vbox_start".

Something like that:

    vbox_start $machine
    sleep 3


Archlinux rulez tongue

My home server running Arch 24/7:
Intel Atom 330, 2GB RAM, 2TB Disks

Offline

Board footer

Powered by FluxBB