4

I'm running Ubuntu server, hosting a virtual machine using an upstart job. I've got it launching on startup, and shutting down the host on exit, but I can't seem to get it to suspend when the host shuts down. If I use initctl stop vmservice, then the suspend happens correctly - but if I shutdown -h now or reboot, it looks like it's just getting killed (I tried putting a sleep in the pre-stop script, and that behaves the same way). Any help would be appreciated.

I'm rather new to upstart, so I'd appreciate any other feedback, too (including, am I doing the "right" thing by calling shutdown in a post-stop?).

my job (the 'start on' was snagged from kdm.conf; .startvm and .stopvm just start and suspend the VM):

start on (filesystem
          and started dbus
          and (graphics-device-added fb0 PRIMARY_DEVICE_FOR_DISPLAY=1
               or drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
               or stopped udevtrigger))
stop on runlevel [016]

pre-stop script
    exec su -c "/home/unprivileged_user/.stopvm" - unprivileged_user
end script

env XORGCONFIG=/etc/X11/xorg.conf
exec su -c "xinit /home/unprivileged_user/.startvm -- /etc/X11/xinit/xserverrc :0" - unprivileged_user

post-stop script
    shutdown -h now
end script

1 Answer 1

4

Upstart will send SIGKILL (as in, kill -9) after 5 seconds of waiting for a pre-stop or the signal sent to the main process.

Use

kill timeout 10

To give yourself 10 seconds to die. You actually can't give yourself longer than that because the shutdown will only wait 10 seconds for any processes to die off before completely shutting down anyway. To make sure your VM is stopped before the full system shutdown begins:

Use this:

stop on starting rc RUNLEVEL=[016]

This will make sure that your VM is fully stopped before the system begins the normal shutdown routine (though the kill timeout is still in effect, so raise that too!)

Also, your SUPER complex start on isn't really necessary at all, though it seems you've copied it from gdm or lightdm.

If you just want your VM to be running whenever the display manager is running, this is far simpler:

start on started lightdm or started gdm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .