VirtualBox

Changeset 6545 in vbox for trunk


Ignore:
Timestamp:
Jan 28, 2008 9:12:41 PM (17 years ago)
Author:
vboxsync
Message:

Linux packages: add mechanism to sanely shutdown VMs on host powerdown

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/linux/vboxdrv.sh

    r5999 r6545  
    2929PATH=$PATH:/bin:/sbin:/usr/sbin
    3030CONFIG="/etc/vbox/vbox.cfg"
     31. "$CONFIG"
     32VBOXMANAGE="$INSTALL_DIR/VBoxManage"
    3133
    3234if [ -f /etc/redhat-release ]; then
     
    3840else
    3941    system=other
     42fi
     43
     44if [ -r /etc/default/virtualbox ]; then
     45  . /etc/default/virtualbox
    4046fi
    4147
     
    154160        fi
    155161        test -z "$maj" && {
    156             rmmod $modname
     162            rmmod $modname 2>/dev/null
    157163            fail "Cannot locate the VirtualBox device"
    158164        }
    159165
    160         mknod -m 0660 $dev c $maj $min || {
    161             rmmod $modname
     166        mknod -m 0660 $dev c $maj $min 2>/dev/null || {
     167            rmmod $modname 2>/dev/null
    162168            fail "Cannot create device $dev with major $maj and minor $min"
    163169        }
    164170    fi
    165171
    166     chown :$groupname $dev || {
    167         rmmod $modname
     172    chown :$groupname $dev 2>/dev/null || {
     173        rmmod $modname 2>/dev/null
    168174        fail "Cannot change owner $groupname for device $dev"
    169175    }
     
    183189}
    184190
     191# enter the following variables in /etc/default/virtualbox:
     192#   SHUTDOWN_USERS="foo bar" 
     193#     check for running VMs of user foo and user bar
     194#   SHUTDOWN=poweroff
     195#   SHUTDOWN=acpibutton
     196#   SHUTDOWN=savestate
     197#     select one of these shutdown methods for running VMs
     198stop_vms() {
     199    wait=0
     200    for i in $SHUTDOWN_USERS; do
     201        # don't create the ipcd directory with wrong permissions!
     202        if [ -d /tmp/.vbox-$i-ipc ]; then
     203            export VBOX_IPC_SOCKETID="$i"
     204            VMS=`$VBOXMANAGE -nologo list runningvms 2>/dev/null`
     205            if [ -n "$VMS" ]; then
     206                if [ "$SHUTDOWN" = "poweroff" ]; then
     207                    begin "Powering off remaining VMs "
     208                    for v in $VMS; do
     209                        $VBOXMANAGE -nologo controlvm $v poweroff
     210                    done
     211                    succ_msg
     212                elif [ "$SHUTDOWN" = "acpibutton" ]; then
     213                    begin "Sending ACPI power button event to remaining VMs "
     214                    for v in $VMS; do
     215                        $VBOXMANAGE -nologo controlvm $v acpipowerbutton
     216                        wait=15
     217                    done
     218                    succ_msg
     219                elif [ "$SHUTDOWN" = "savestate" ]; then
     220                    begin "Saving state of remaining VMs "
     221                    for v in $VMS; do
     222                        $VBOXMANAGE -nologo controlvm $v savestate
     223                    done
     224                    succ_msg
     225                fi
     226            fi
     227        fi
     228    done
     229    # wait for some seconds when doing ACPI shutdown
     230    if [ "$wait" -ne 0 ]; then
     231        log_daemon_msg "Waiting for $wait seconds for VM shutdown"
     232        sleep $wait
     233        log_end_msg
     234    fi
     235}
     236
    185237restart() {
    186238    stop && start
     
    189241
    190242setup() {
    191     . "$CONFIG"
    192243    stop
    193244    if find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
     
    207258    if running; then
    208259        echo "VirtualBox kernel module is loaded."
     260        for i in $SHUTDOWN_USERS; do
     261            # don't create the ipcd directory with wrong permissions!
     262            if [ -d /tmp/.vbox-$i-ipc ]; then
     263                export VBOX_IPC_SOCKETID="$i"
     264                VMS=`$VBOXMANAGE -nologo list runningvms 2>/dev/null`
     265                if [ -n "$VMS" ]; then
     266                    echo "The following VMs are currently running:"
     267                    for v in $VMS; do
     268                       echo "  $v"
     269                    done
     270                fi
     271            fi
     272        done
    209273    else
    210274        echo "VirtualBox kernel module is not loaded."
     
    217281    ;;
    218282stop)
     283    stop_vms
    219284    stop
     285    ;;
     286stop_vms)
     287    stop_vms
    220288    ;;
    221289restart)
     
    229297    ;;
    230298*)
    231     echo "Usage: $0 {start|stop|restart|status|setup}"
     299    echo "Usage: $0 {start|stop|stop_vms|restart|status|setup}"
    232300    exit 1
    233301esac
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette