I run my VBoxes in a chroot, which means I have to run two init
scripts...

The primary one:
----- s n i p -----
#!/bin/sh

case "$1" in
    start) 
        if [ ! -d /mnt/chroots/VirtualBox/share/home ]; then
            umount /mnt/chroots/VirtualBox/share
            mount /mnt/chroots/VirtualBox/share
        fi

        mods=`lsmod | grep vbox | wc -l`
        if [ $mods -eq 0 ]; then
            chroot /mnt/chroots/VirtualBox /etc/init.d/vboxdrv start
        fi

        chroot /mnt/chroots/VirtualBox su - turbo -c "/etc/init.d/vboxhst start"
        ;;

    stop)
        chroot /mnt/chroots/VirtualBox su - turbo -c "/etc/init.d/vboxhst stop"
        ;;

    forcequit)
        chroot /mnt/chroots/VirtualBox su - turbo -c "/etc/init.d/vboxhst 
forcequit"
        ;;

    *)
        echo "Usage: $0 {start|stop}" >&2
        exit 3
        ;;
esac

exit 0
----- s n i p -----


The secondary one:
----- s n i p -----
#!/bin/sh

unset MAIL
USER=turbo
LOGNAME=turbo
HOME=/home/turbo
HOSTS="Astrix,Windows XP Professional,Windows Vista,Windows 7,Ubuntu IMAP"
CACHE=/var/cache/vbox/xbox-vms
export USER LOGNAME HOME

case "$1" in
    start) 
        echo -n "Starting VM: "
        if [ -f $CACHE ]; then
            cat $CACHE | \
                while read host; do
                    echo -n "'$host' "
                    /usr/bin/VBoxManage -nologo startvm "$host" -type vrdp
                done

            rm -f $CACHE
        else
            echo "$HOSTS" | sed 's@,@\
@g' | while read host; do
                echo -n "'$host' "
                /usr/bin/VBoxManage -nologo startvm "$host" -type vrdp
            done
        fi
        ;;

    stop)
        echo -n "Suspending VM: "
        /usr/bin/VBoxManage -nologo list runningvms | \
            sed -e 's@ {.*@@' -e 's@"@@g' > $CACHE

        cat $CACHE | \
            while read host; do
                echo -n "'$host' "
                /usr/bin/VBoxManage -nologo controlvm "$host" savestate
            done
        ;;

    forcequit)
        echo "Shutting down VM: "
        /usr/bin/VBoxManage -nologo list runningvms | \
            sed -e 's@ {.*@@' -e 's@"@@g' | \
            while read host; do
                echo -n "  '$host' "
                /usr/bin/VBoxManage -nologo controlvm "$host" poweroff
            done
        ;;

    *)
        echo "Usage: $0 {start|stop}" >&2
        exit 3
        ;;
esac

exit 0
----- s n i p -----


The nice thing about this is that it remembers what hosts where
running at previous shutdown, and only starts those... Not all 
of them! I have a bunch of machines I start only temporarily when
needed...


------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web.   Learn how to 
best implement a security strategy that keeps consumers' information secure 
and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl 
_______________________________________________
VBox-users-community mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vbox-users-community

Reply via email to