Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Make upstart job wait for VirtualBox to end gracefully

  1. #1
    Join Date
    Jun 2007
    Location
    Australia, Victoria
    Beans
    144
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Question Make upstart job wait for VirtualBox to end gracefully

    Hello everyone,

    I've been trying for hours and hours to figure out a way of running a VirtualBox machine when my system boots using upstart. I've been able to get it to boot successfully, but I can't seem to make upstart wait for it to close properly. Instead the Virtual Machine just gets killed, and loses all its active state. The guest is configured to immediately shutdown when it receives the acpishutdown signal from VBoxManage.

    This is my upstart script:
    Code:
    #Start Transmission's Virtual Machine on boot
    
    description	"Transmission Virtual Machine"
    
    start on (local-filesystems and net-device-up IFACE=eth0)
    stop on runlevel [016]
    
    console log
    
    respawn
    respawn limit 5 10
    kill timeout 20
    
    pre-stop script
    	exec sudo -u sean VBoxManage controlvm "Transmission Server" acpipowerbutton
    	inactive=0
    	while [ "$inactive" == "0" ]; do
    		inactive=`vboxmanage showvminfo "Transmission Server" | grep -E "No active facilities." | wc -l`
    		sleep 0.5s
    	done
    end script
    
    script
    	exec sudo -u sean VBoxHeadless -startvm "Transmission Server"
    end script
    I had tried it without my attempt at the loop, and obviously that didn't work. I also tried putting all of the pre-stop script in an external script - and that partly worked, although then upstart would hang indefinitely and I also could not re-start the Virtual Machine without first rebooting the host. So that approach went from no delay, to an infinite delay.

    This must be possible to do! How can I just tell upstart to wait for 20 seconds for the guest to turn off?

  2. #2
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Make upstart job wait for VirtualBox to end gracefully

    I gave up on using upstart for my vbox script.

    You can find my script here:
    http://charlesa.net/scripts/linux/vi...ipt-ubuntu.php

    There is also a script another member was working on which can be found here:
    http://ubuntuforums.org/showthread.php?t=1844885
    Last edited by CharlesA; April 16th, 2013 at 05:47 AM. Reason: updated url
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  3. #3
    Join Date
    Jun 2007
    Location
    Australia, Victoria
    Beans
    144
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Make upstart job wait for VirtualBox to end gracefully

    Hmm, I really would have preferred to use upstart - it's much more user-friendly. Would this be a bug possibly? Even if I make the pre-stop command the VBoxManage savestate command, it will save the state but then get killed and not restore from it. Virtual Box lists it as "Aborted". Upstart just will not wait any time at all for it to end.

  4. #4
    Join Date
    Jun 2007
    Location
    Australia, Victoria
    Beans
    144
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Make upstart job wait for VirtualBox to end gracefully

    Having said that, the init.d script does work perfectly. Thanks!

  5. #5
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Make upstart job wait for VirtualBox to end gracefully

    Glad you got it (sorta) sorted.

    Don't forget to mark the thread as solved from thread tools.
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  6. #6
    Join Date
    Jun 2007
    Location
    Australia, Victoria
    Beans
    144
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Init.d Respawn?

    Well, I'm not 100% happy with it though...
    The upstart job (if it worked) would boot my VM without needing it to be in the "Saved State", and it would also respawn it if it happened to shut itself down.

    Since upstart appears not to like Virtual Box, how would I add the respawn to the init.d script? Modifying it to boot my VM instead of all saved VMs shouldn't be too hard, but the respawn I'm not sure about.

  7. #7
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Init.d Respawn?

    Check out the thread I linked to earlier by doas777
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  8. #8
    Join Date
    Jun 2007
    Location
    Australia, Victoria
    Beans
    144
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Make upstart job wait for VirtualBox to end gracefully

    Ah yes, I see now. This is the post: http://ubuntuforums.org/showpost.php...3&postcount=28. Very handy.

    Thanks!

  9. #9
    Join Date
    Jun 2007
    Location
    Australia, Victoria
    Beans
    144
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Make upstart job wait for VirtualBox to end gracefully

    So I suppose it's reasons like this example that explain why upstart hasn't completely replaced all of the init.d scripts...

  10. #10
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Make upstart job wait for VirtualBox to end gracefully

    Quote Originally Posted by seanlano View Post
    Ah yes, I see now. This is the post: http://ubuntuforums.org/showpost.php...3&postcount=28. Very handy.

    Thanks!
    That would be it.
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

Page 1 of 2 12 LastLast

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
  •