- def call(self, name, callback, persist, *args, **kw):
- proc = subprocess.Popen(*args, **kw)
- procinfo = ProcessInfo(name, proc, args, kw, callback, persist)
- self.namemap[name] = self.pidmap[proc.pid] = procinfo
+ def register(self, name, command, callback=None, persist=False,
+ *args, **kw):
+ self.services[name] = ProcessInfo(name, command, callback, persist,
+ args, kw)
+
+ def unregister(self, name):
+ del self.services[name]
+
+ def _call(self, pi):
+ pi.start()
+ self.namemap[pi.name] = self.pidmap[pi.process.pid] = pi
+
+ def call(self, name, command, callback=None, persist=False, *args, **kw):
+ pi = ProcessInfo(name, command, callback, persist, args, kw)
+ self._call(pi)
+
+ def start(self, name):
+ assert name not in self.namemap
+ self._call(self.services[name])
+
+ def stop(self, name):
+ assert name in self.namemap
+ self.namemap[name].stop()
+
+ def restart(self, name):
+ logging.debug(u'ProcessManager.restart(%s)', name)
+ if name in self.namemap:
+ self.namemap[name].stop()
+ self.namemap[name].wait()
+ self.namemap[name].restart()
+ else:
+ self.namemap[name].start()
+
+ def kill(self, name, signum):
+ assert name in self.namemap
+ self.namemap[name].kill(name, stop)