Author: justi9
Date: 2008-12-15 13:46:44 -0500 (Mon, 15 Dec 2008)
New Revision: 3001
Modified:
mgmt/trunk/cumin/python/cumin/tools.py
Log:
Try really hard to make the mint subprocess die
Modified: mgmt/trunk/cumin/python/cumin/tools.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/tools.py 2008-12-15 15:46:40 UTC (rev 3000)
+++ mgmt/trunk/cumin/python/cumin/tools.py 2008-12-15 18:46:44 UTC (rev 3001)
@@ -7,6 +7,7 @@
from getpass import getpass
from psycopg2 import IntegrityError
from subprocess import Popen
+from time import sleep
from util import *
from cumin import Cumin, CuminServer, CuminConfig
@@ -443,21 +444,39 @@
opt = CommandOption(self, "ssl")
opt.description = "Serve web pages using SSL"
- def start_mint_process(self, config, opts):
- args = ["mint-server",
- "--data", self.config.data,
- "--log-file", self.config.log_file,
- "--log-level", self.config.log_level,
- "--expire-frequency", str(self.config.expire_frequency),
- "--expire-threshold", str(self.config.expire_threshold)]
+ class MintProcess(object):
+ def __init__(self):
+ self.proc = None
- if "debug" in opts or config.debug:
- args.append("--debug")
+ def start(self, config, opts):
+ args = ["mint-server",
+ "--data", config.data,
+ "--log-file", config.log_file,
+ "--log-level", config.log_level,
+ "--expire-frequency", str(config.expire_frequency),
+ "--expire-threshold", str(config.expire_threshold)]
- pop = Popen(args)
+ if "debug" in opts or config.debug:
+ args.append("--debug")
- return pop.pid
+ self.proc = Popen(args)
+ def stop(self):
+ os.kill(self.proc.pid, signal.SIGTERM)
+
+ for i in range(10):
+ code = self.proc.poll()
+
+ if code is not None:
+ return
+
+ sleep(1)
+
+ os.kill(self.proc.pid, signal.SIGKILL)
+
+ log.warn("Mint subprocess %i wouldn't go gracefully",
+ self.proc.pid)
+
def do_run(self, opts, args):
self.config.load_dict(opts)
@@ -494,25 +513,23 @@
log.error("SSL key file '%s' not found" % kpath)
sys.exit(1)
- mint_pid = None
+ mint_proc = self.MintProcess()
try:
- app.start()
-
try:
- mint_pid = self.start_mint_process(self.config, opts)
+ mint_proc.start(self.config, opts)
except:
log.exception("Failed starting mint process")
+ app.start()
+
try:
server.start()
finally:
server.stop()
finally:
- if mint_pid is not None:
- os.kill(mint_pid, signal.SIGTERM)
-
app.stop()
+ mint_proc.stop()
class CuminTestTool(BaseCuminTool):
def __init__(self, name):
Show replies by date