+ def _call(self, pi):
+ pi.start()
+ self.namemap[pi.name] = self.pidmap[pi.process.pid] = pi
+
+ def once(self, name, command=None, callback=None, persist=False,
+ max_errors=3, *args, **kwargs):
+ log.debug(u'ProcessManager.once(%s, %s, %s, %s, %s, %s, %s)',
+ name, command, callback, persist, max_errors, args, kwargs)
+ if not isinstance(name, ProcessInfo):
+ pi = ProcessInfo(name, command, callback, persist, max_errors,
+ args, kwargs)
+ else:
+ pi = name
+ name = pi.name
+ assert not self.has(name)
+ self._call(pi)
+ return pi
+
+ def start(self, name):
+ log.debug(u'ProcessManager.start(%s)', name)
+ if isinstance(name, ProcessInfo):
+ name = name.name
+ if name not in self.namemap:
+ self._call(self.services[name])
+ return True
+ return False
+
+ def stop(self, name):
+ log.debug(u'ProcessManager.stop(%s)', name)
+ if isinstance(name, ProcessInfo):
+ name = name.name
+ if name in self.namemap:
+ self.namemap[name].stop()
+ return True
+ return False
+
+ def restart(self, name):
+ log.debug(u'ProcessManager.restart(%s)', name)
+ if isinstance(name, ProcessInfo):
+ name = name.name
+ # we have to check first in namemap in case is an unregistered
+ # process (added with once())
+ if name in self.namemap:
+ pi = self.namemap[name]
+ # the process will change its PID, so we delete it while we know it
+ del self.pidmap[pi.process.pid]
+ pi.stop()
+ pi.process.wait()
+ pi.restart()
+ # add the new PID
+ self.pidmap[pi.process.pid] = pi
+ return True
+ else:
+ self.start(name)
+ return False
+
+ def kill(self, name, signum):
+ log.debug(u'ProcessManager.kill(%s, %s)', name, signum)
+ if isinstance(name, ProcessInfo):
+ name = name.name
+ if name in self.namemap:
+ self.namemap[name].kill(name, stop)
+ return True
+ return False
+
+ def sigchild_handler(self, signum, stack_frame=None):
+ log.debug(u'ProcessManager.sigchild_handler(%s)', signum)