Author: eelco
Date: Mon Mar 19 18:07:05 2012
New Revision: 33269
URL: https://nixos.org/websvn/nix/?rev=33269&sc=1

Log:
* Handle jobs that fail while a post-start script is waiting for them.

Modified:
   nixos/trunk/modules/system/activation/switch-to-configuration.sh
   nixos/trunk/modules/system/upstart/upstart.nix

Modified: nixos/trunk/modules/system/activation/switch-to-configuration.sh
==============================================================================
--- nixos/trunk/modules/system/activation/switch-to-configuration.sh    Mon Mar 
19 18:06:18 2012        (r33268)
+++ nixos/trunk/modules/system/activation/switch-to-configuration.sh    Mon Mar 
19 18:07:05 2012        (r33269)
@@ -102,6 +102,17 @@
 declare -A tasks=(@tasks@)
 declare -A noRestartIfChanged=(@noRestartIfChanged@)
 
+start_() {
+    local job="$1"
+    if start --quiet "$job"; then
+        # Handle services that cancel themselves.
+        if ! [ -n "${tasks[$job]}" ]; then
+            local status=$(status "$job")
+            [[ "$status" =~ start/running ]] || echo "job ‘$job’ failed to 
start!"
+        fi
+    fi
+}
+
 # Restart all running jobs that have changed.  (Here "running" means
 # all jobs that don't have a "stop" goal.)  We use the symlinks in
 # /var/run/upstart-jobs (created by each job's pre-start script) to
@@ -118,7 +129,7 @@
     # Note: can't use "restart" here, since that only restarts the
     # job's main process.
     stop --quiet "$job" || true
-    start --quiet "$job" || true
+    start_ "$job" || true
 done
 
 # Start all jobs that are not running but should be.  The "should be"
@@ -141,7 +152,7 @@
     else
         if ! grep -q "^start on" "$jobsDir/$job.conf"; then continue; fi
         echo "starting service ‘$job’..."
-        start --quiet "$job" || true
+        start_ "$job" || true
     fi
     
 done

Modified: nixos/trunk/modules/system/upstart/upstart.nix
==============================================================================
--- nixos/trunk/modules/system/upstart/upstart.nix      Mon Mar 19 18:06:18 
2012        (r33268)
+++ nixos/trunk/modules/system/upstart/upstart.nix      Mon Mar 19 18:07:05 
2012        (r33269)
@@ -175,10 +175,16 @@
       # Check whether the current job has been stopped.  Used in
       # post-start jobs to determine if they should continue.
       stop_check() {
-          if [[ "$(status)" =~ stop/ ]]; then
+          local status="$(status)"
+          if [[ "$status" =~ stop/ ]]; then
               echo "job asked to stop!"
               return 1
           fi
+          if [[ "$status" =~ respawn/ ]]; then
+              echo "job respawning unexpectedly!"
+              stop
+              return 1
+          fi
           return 0
       }
     '';
_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits

Reply via email to