Author: tmckay
Date: 2011-11-08 21:35:27 +0000 (Tue, 08 Nov 2011)
New Revision: 5123
Modified:
trunk/cumin/bin/cumin
Log:
Send SIGINT to child processes first, then wait up to 10 seconds
for all children to exit before issuing SIGKILL
Modified: trunk/cumin/bin/cumin
===================================================================
--- trunk/cumin/bin/cumin 2011-11-08 20:36:56 UTC (rev 5122)
+++ trunk/cumin/bin/cumin 2011-11-08 21:35:27 UTC (rev 5123)
@@ -6,6 +6,7 @@
import sys
import signal
import traceback
+from datetime import datetime, timedelta
home = os.environ.get("CUMIN_HOME",
os.path.normpath("/usr/share/cumin"))
sys.path.append(os.path.join(home, "python"))
@@ -166,8 +167,34 @@
else:
start(app, "Restart")
finally:
- for app in apps:
- app[PROCESS] and os.kill(app[PROCESS].pid, signal.SIGTERM)
+ # Try a ctrl-C first
+ log.info("Send SIGINT to all children")
+ complete = 0
+ for app in apps:
+ if app[PROCESS]:
+ complete += 1
+ os.kill(app[PROCESS].pid, signal.SIGINT)
+
+ # Give children 10 seconds to exit, then bail
+ then = datetime.now()
+ while complete != 0:
+ for app in apps:
+ poll = app[PROCESS] and app[PROCESS].poll()
+ if poll is not None:
+ app[PROCESS] = None
+ complete -= 1
+
+ if complete == 0:
+ log.info("All children exited")
+ break
+
+ sleep(0.25)
+ if datetime.now() - then > timedelta(seconds=10):
+ for app in apps: # just to be paranoid
+ app[PROCESS] and os.kill(app[PROCESS].pid, signal.SIGKILL)
+ log.info("Timed out waiting for children, exited")
+ break
+
return return_code
if __name__ == "__main__":
Show replies by date