From 646d67465c264ef490372a512c79f0bf29b27394 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Fri, 16 Mar 2012 21:24:51 +0000
Subject: [PATCH] * Upstart stupidly doesn't kill post-start scripts if we do
 "stop   JOB", but it does kill the job's main process.  So if the post-start 
  script if waiting for the job's main process to reach some state, it   may
 hang forever.  Thus, the post-start script should monitor   whether its job
 has been requested to stop and exit in that case.

svn path=/nixos/trunk/; revision=33176
---
 modules/services/networking/portmap.nix | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/modules/services/networking/portmap.nix b/modules/services/networking/portmap.nix
index a6d799ec377b..cde4bb6a9553 100644
--- a/modules/services/networking/portmap.nix
+++ b/modules/services/networking/portmap.nix
@@ -87,7 +87,10 @@ in
           ''
             # Portmap forks into the background before it starts
             # listening, so wait until its ready.
-            while ! nc -z localhost 111; do sleep 1; done
+            while ! nc -z localhost 111; do
+                if [[ "$(status)" =~ stop/ ]]; then exit; fi
+                sleep 1
+            done
           '';
       };