diff --git a/modules/system/activation/switch-to-configuration.sh b/modules/system/activation/switch-to-configuration.sh index ffc9845622c..3249ee3ea34 100644 --- a/modules/system/activation/switch-to-configuration.sh +++ b/modules/system/activation/switch-to-configuration.sh @@ -110,7 +110,11 @@ EOF # forget about current sessions. # Idem for the emergeny-shell, because its `console owner' # line screws up the X server. - if echo "$job" | grep -q "^shutdown$\|^control-alt-delete$\|^xserver$\|^dbus$\|^disnix$\|^emergency-shell$"; then continue; fi + # Idem for xendomains because we don't want to save/restore + # Xen domains unless we have to. + # TODO: Jobs should be able to declare that they should not be + # auto-restarted. + if echo "$job" | grep -q "^shutdown$\|^control-alt-delete$\|^xserver$\|^dbus$\|^disnix$\|^emergency-shell$\|^xendomains$"; then continue; fi if ! test -e "$oldJobs/$job.conf"; then echo "starting $job..." diff --git a/modules/virtualisation/xen-dom0.nix b/modules/virtualisation/xen-dom0.nix index 65158bc5f81..e10713466f7 100644 --- a/modules/virtualisation/xen-dom0.nix +++ b/modules/virtualisation/xen-dom0.nix @@ -108,11 +108,39 @@ in pkgs.utillinux pkgs.bash xen pkgs.pciutils pkgs.procps ]; - preStart = "${xen}/sbin/xend start"; + preStart = + '' + ${xen}/sbin/xend start + + # Wait until Xend is running. + for ((i = 0; i < 60; i++)); do echo "waiting for xend..."; ${xen}/sbin/xend status && break; done + + ${xen}/sbin/xend status || exit 1 + ''; postStop = "${xen}/sbin/xend stop"; }; + jobs.xendomains = + { description = "Automatically starts, saves and restores Xen domains on startup/shutdown"; + + startOn = "started xend"; + + stopOn = "starting shutdown and stopping xend"; + + path = [ pkgs.xen ]; + + environment.XENDOM_CONFIG = "${xen}/etc/sysconfig/xendomains"; + + preStart = + '' + mkdir -p /var/lock/subsys -m 755 + ${xen}/etc/init.d/xendomains start + ''; + + postStop = "${xen}/etc/init.d/xendomains stop"; + }; + # To prevent a race between dhclient and xend's bridge setup # script (which renames eth* to peth* and recreates eth* as a # virtual device), start dhclient after xend.