def __init__(self): self.root = None self.web = None self.mode = MULTI_SERVER_MODE self.node = None self.script = "appmain.py" self.process = ProcessMonitor() self.service = service.MultiService() self.start_time = 0
def setUp(self): """ Create an L{ProcessMonitor} wrapped around a fake reactor. """ self.reactor = DummyProcessReactor() self.pm = ProcessMonitor(reactor=self.reactor) self.pm.minRestartDelay = 2 self.pm.maxRestartDelay = 10 self.pm.threshold = 10
def makeService(config): s = ProcessMonitor() s.threshold = config["threshold"] s.killTime = config["killtime"] s.minRestartDelay = config["minrestartdelay"] s.maxRestartDelay = config["maxrestartdelay"] s.addProcess(" ".join(config["args"]), config["args"]) return s
def run_zeo(db): """Spawns a zeo daemon and restart it if it crashes""" runzeo = 'bin/runzeo' # XXX: compat mode for buildout-less runs if not os.path.exists('bin/runzeo'): runzeo = 'runzeo' pm = ProcessMonitor() pm.addProcess('zeo', [ '/bin/sh', '-c', '%s -f %s/data.fs -a %s/socket >%s/zeo.log 2>&1' % (runzeo, db, db, db) ], env=os.environ) pm.startService()
def test_addProcessEnv(self): """ L{ProcessMonitor.addProcess} takes an C{env} parameter that is passed to C{spawnProcess}. """ spawnedProcesses = [] def fakeSpawnProcess(*args, **kwargs): spawnedProcesses.append((args, kwargs)) self.patch(reactor, "spawnProcess", fakeSpawnProcess) pm = ProcessMonitor() pm.active = True fakeEnv = {"KEY": "value"} pm.addProcess("foo", ["foo"], uid=1, gid=2, env=fakeEnv) self.assertEquals(spawnedProcesses, [((pm.protocols["foo"], "foo", ["foo"]), { "uid": 1, "gid": 2, "env": fakeEnv })])
def test_addProcess(self): """ L{ProcessMonitor.addProcess} starts the named program and tracks the resulting process, a protocol for collecting its stdout, and the time it was started. """ spawnedProcesses = [] def fakeSpawnProcess(*args, **kwargs): spawnedProcesses.append((args, kwargs)) self.patch(reactor, "spawnProcess", fakeSpawnProcess) pm = ProcessMonitor() pm.active = True pm.addProcess("foo", ["arg1", "arg2"], uid=1, gid=2) self.assertEquals(pm.processes, {"foo": (["arg1", "arg2"], 1, 2, {})}) self.assertEquals(pm.protocols.keys(), ["foo"]) lp = pm.protocols["foo"] self.assertEquals(spawnedProcesses, [((lp, "arg1", ["arg1", "arg2"]), { "uid": 1, "gid": 2, "env": {} })])
def setUp(self): """ Create reactor and process monitor. """ self.reactor = DummyProcessReactor() self.pm = ProcessMonitor(reactor=self.reactor)