Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Make upstart job wait for VirtualBox to end gracefully

  1. #11
    Join Date
    Feb 2013
    Beans
    1

    Re: Make upstart job wait for VirtualBox to end gracefully

    This conf works with Ubuntu 12.04 and VirtualBox 4.2:

    Code:
    description "Virtual Machine"
    
    start on (local-filesystems and net-device-up IFACE=eth0)
    stop on runlevel [016]
    
    env vm_uid_or_name=d82c5d45-e113-4332-8de3-51c6251057c8
    env vm_comment=some-comment
    env uid=username-under-which-vm-was-created
    
    console log
    
    #respawn
    #respawn limit 5 10
    kill timeout 120
    
    script
        exec sudo -u $uid VBoxHeadless --startvm "$vm_uid_or_name" --comment "$vm_comment"
    end script
    
    pre-stop script
        echo "Send ACPI poweroff event to $vm_uid_or_name"
        sudo -u $uid VBoxManage controlvm "$vm_uid_or_name" acpipowerbutton
        echo "Wait while state is 'running'"
        while sudo -u $uid VBoxManage showvminfo "$vm_uid_or_name" | grep -E "State:\s+running" -q
        do
            sleep 0.5s
        done
        echo "Complite ACPI waiting"
    end script

  2. #12
    Join Date
    Oct 2010
    Beans
    19

    Re: Make upstart job wait for VirtualBox to end gracefully

    I know it is already solved, but my upstart configuration and two scripts here do gracefully shutdown even on reboot, shutdown or power-button events:

    http://askubuntu.com/questions/10129.../278705#278705

    See the post from tombert.

  3. #13
    Join Date
    Oct 2010
    Beans
    19

    Lightbulb Re: Make upstart job wait for VirtualBox to end gracefully

    Quote Originally Posted by valery1707 View Post
    This conf works with Ubuntu 12.04 and VirtualBox 4.2:

    Code:
    description "Virtual Machine"
    
    start on (local-filesystems and net-device-up IFACE=eth0)
    stop on runlevel [016]
    
    env vm_uid_or_name=d82c5d45-e113-4332-8de3-51c6251057c8
    env vm_comment=some-comment
    env uid=username-under-which-vm-was-created
    
    console log
    
    #respawn
    #respawn limit 5 10
    kill timeout 120
    
    script
        exec sudo -u $uid VBoxHeadless --startvm "$vm_uid_or_name" --comment "$vm_comment"
    end script
    
    pre-stop script
        echo "Send ACPI poweroff event to $vm_uid_or_name"
        sudo -u $uid VBoxManage controlvm "$vm_uid_or_name" acpipowerbutton
        echo "Wait while state is 'running'"
        while sudo -u $uid VBoxManage showvminfo "$vm_uid_or_name" | grep -E "State:\s+running" -q
        do
            sleep 0.5s
        done
        echo "Complite ACPI waiting"
    end script
    This script power-offs the machine immediately since upstart is sending the SIGTERM to the process. After the timeout it send the SIGKILL.
    You can improve it by adding:
    Code:
    kill signal SIGCONT
    Also the acpipowerbutton does not work reliably always since Windows might show the shutdown confirmation dialog preventing from shutdown. You could improve this by sending the shutdown directly to the guest using guestcontrol.

    Next I would recommend running the stop script before entering the runlevel 0, which could be solved by using:
    Code:
    stop on starting rc RUNLEVEL=[!2]

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •