From ad93acc29552aa254dac6aa02695c470e316104b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Jun 2010 16:04:08 +0000 Subject: [PATCH] * Make all Upstart jobs shut down on the `starting shutdown' event. This ensures that they're gone by the time the shutdown job runs, so it doesn't have to stop them itself. * Don't respawn tasks, as it doesn't seem useful (if they fail they're likely to fail again if they're restarted). svn path=/nixos/trunk/; revision=22099 --- modules/system/upstart-events/runlevel.nix | 6 +++--- modules/system/upstart-events/shutdown.nix | 25 +++++++++------------- modules/system/upstart/upstart.nix | 4 ++-- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/modules/system/upstart-events/runlevel.nix b/modules/system/upstart-events/runlevel.nix index 750d9a07f50c..96864594509c 100644 --- a/modules/system/upstart-events/runlevel.nix +++ b/modules/system/upstart-events/runlevel.nix @@ -14,9 +14,9 @@ with pkgs.lib; script = '' case "$RUNLEVEL" in - 0) initctl start shutdown MODE=poweroff;; - 1) initctl start shutdown MODE=maintenance;; - 6) initctl start shutdown MODE=reboot;; + 0) initctl start shutdown --no-wait MODE=poweroff;; + 1) initctl start shutdown --no-wait MODE=maintenance;; + 6) initctl start shutdown --no-wait MODE=reboot;; *) echo "Unsupported runlevel: $RUNLEVEL";; esac ''; diff --git a/modules/system/upstart-events/shutdown.nix b/modules/system/upstart-events/shutdown.nix index ff208a80b5a2..66d5a7b588b3 100644 --- a/modules/system/upstart-events/shutdown.nix +++ b/modules/system/upstart-events/shutdown.nix @@ -9,8 +9,12 @@ with pkgs.lib; task = true; + stopOn = ""; # must override the default ("starting shutdown") + environment = { MODE = "poweroff"; }; + extraConfig = "console owner"; + script = '' set +e # continue in case of errors @@ -29,24 +33,10 @@ with pkgs.lib; export PATH=${pkgs.utillinux}/bin:${pkgs.utillinux}/sbin:$PATH - # Set the hardware clock to the system time. - echo "setting the hardware clock..." - hwclock --systohc --utc - - # Do an initial sync just in case. sync - # Stop all Upstart jobs. - initctl list | while IFS=", " read jobName status rest; do - if test "$jobName" != shutdown -a "$status" != "stop/waiting"; then - echo "stopping $jobName..." - stop "$jobName" - fi - done - - # Kill all remaining processes except init and this one. echo "sending the TERM signal to all processes..." kill -TERM -1 @@ -64,12 +54,17 @@ with pkgs.lib; echo "" echo "<<< Maintenance shell >>>" echo "" - while ! ${pkgs.bash}/bin/bash --login; do true; done + ${pkgs.pam_login}/bin/login root initctl emit -n startup exit 0 fi + # Set the hardware clock to the system time. + echo "setting the hardware clock..." + hwclock --systohc --utc + + # Unmount helper functions. getMountPoints() { cat /proc/mounts \ diff --git a/modules/system/upstart/upstart.nix b/modules/system/upstart/upstart.nix index b3a6c0b1c9e8..3110f376eece 100644 --- a/modules/system/upstart/upstart.nix +++ b/modules/system/upstart/upstart.nix @@ -75,7 +75,7 @@ let ''} ${optionalString job.task "task"} - ${optionalString job.respawn "respawn"} + ${optionalString (!job.task && job.respawn) "respawn"} ${optionalString (job.preStop != "") '' pre-stop script @@ -153,7 +153,7 @@ let stopOn = mkOption { type = types.string; - default = "shutdown"; + default = "starting shutdown"; description = '' The Upstart event that triggers this job to be stopped. '';