def testAll(self): pid = getPid('test', 'default') self.failIf(pid) writePidFile('test', 'default') waitPidFile('test', 'default') pid = getPid('test', 'default') self.assertEquals(os.getpid(), pid) deletePidFile('test', 'default')
def startManager(self, name, flowNames): """ Start the manager as configured in the manager directory for the given manager name, together with the given flows. @returns: whether or not the manager daemon started """ self.info("Starting manager %s" % name) self.debug("Starting manager with flows %r" % flowNames) managerDir = os.path.join(self.managersDir, name) planetFile = os.path.join(managerDir, 'planet.xml') if not os.path.exists(planetFile): raise errors.FatalError, \ "Planet file %s does not exist" % planetFile self.info("Loading planet %s" % planetFile) flowsDir = os.path.join(managerDir, 'flows') flowFiles = [] for flowName in flowNames: flowFile = os.path.join(flowsDir, "%s.xml" % flowName) if not os.path.exists(flowFile): raise errors.FatalError, \ "Flow file %s does not exist" % flowFile flowFiles.append(flowFile) self.info("Loading flow %s" % flowFile) pid = getPid('manager', name) if pid: if checkPidRunning(pid): raise errors.FatalError, \ "Manager %s is already running (with pid %d)" % (name, pid) else: # there is a stale PID file, warn about it, remove it and # continue self.warning("Removing stale pid file %d for manager %s", pid, name) deletePidFile('manager', name) dirOptions = self._getDirOptions() command = "flumotion-manager %s -D --daemonize-to %s " \ "--service-name %s %s %s" % ( dirOptions, configure.daemondir, name, planetFile, " ".join(flowFiles)) self.debug("starting process %s" % command) retval = self.startProcess(command) if retval == 0: self.debug("Waiting for pid for manager %s" % name) pid = waitPidFile('manager', name) if pid: self.info("Started manager %s with pid %d" % (name, pid)) return True else: self.warning("manager %s could not start" % name) return False self.warning("manager %s could not start (return value %d)" % ( name, retval)) return False
def startWorker(self, name): """ Start the worker as configured in the worker directory for the given worker name. @returns: whether or not the worker daemon started """ self.info("Starting worker %s" % name) if self.checkDisabled('worker', name): print "worker %s is disabled, cannot start" % name return workerFile = os.path.join(self.workersDir, "%s.xml" % name) if not os.path.exists(workerFile): raise errors.FatalError, \ "Worker file %s does not exist" % workerFile pid = getPid('worker', name) if pid: if checkPidRunning(pid): raise errors.FatalError, \ "Worker %s is already running (with pid %d)" % (name, pid) else: # there is a stale PID file, warn about it, remove it and # continue self.warning("Removing stale pid file %d for worker %s", pid, name) deletePidFile('worker', name) # we are sure the worker is not running and there's no pid file self.info("Loading worker %s" % workerFile) dirOptions = self._getDirOptions() command = "flumotion-worker %s -D --daemonize-to %s " \ "--service-name %s %s" % ( dirOptions, configure.daemondir, name, workerFile) self.debug("Running %s" % command) retval = self.startProcess(command) if retval == 0: self.debug("Waiting for pid for worker %s" % name) pid = waitPidFile('worker', name) if pid: self.info("Started worker %s with pid %d" % (name, pid)) return True else: self.warning("worker %s could not start" % name) return False self.warning("worker %s could not start (return value %d)" % (name, retval)) return False
def startWorker(self, name): """ Start the worker as configured in the worker directory for the given worker name. @returns: whether or not the worker daemon started """ self.info("Starting worker %s" % name) if self.checkDisabled('worker', name): print "worker %s is disabled, cannot start" % name return workerFile = os.path.join(self.workersDir, "%s.xml" % name) if not os.path.exists(workerFile): raise errors.FatalError, \ "Worker file %s does not exist" % workerFile pid = getPid('worker', name) if pid: if checkPidRunning(pid): raise errors.FatalError, \ "Worker %s is already running (with pid %d)" % (name, pid) else: # there is a stale PID file, warn about it, remove it and # continue self.warning("Removing stale pid file %d for worker %s", pid, name) deletePidFile('worker', name) # we are sure the worker is not running and there's no pid file self.info("Loading worker %s" % workerFile) dirOptions = self._getDirOptions() command = "flumotion-worker %s -D --daemonize-to %s " \ "--service-name %s %s" % ( dirOptions, configure.daemondir, name, workerFile) self.debug("Running %s" % command) retval = self.startProcess(command) if retval == 0: self.debug("Waiting for pid for worker %s" % name) pid = waitPidFile('worker', name) if pid: self.info("Started worker %s with pid %d" % (name, pid)) return True else: self.warning("worker %s could not start" % name) return False self.warning("worker %s could not start (return value %d)" % ( name, retval)) return False
def startManager(self, name, flowNames): """ Start the manager as configured in the manager directory for the given manager name, together with the given flows. @returns: whether or not the manager daemon started """ self.info("Starting manager %s" % name) if self.checkDisabled('manager', name): print "manager %s is disabled, cannot start" % name return self.debug("Starting manager with flows %r" % flowNames) managerDir = os.path.join(self.managersDir, name) planetFile = os.path.join(managerDir, 'planet.xml') if not os.path.exists(planetFile): raise errors.FatalError, \ "Planet file %s does not exist" % planetFile self.info("Loading planet %s" % planetFile) flowsDir = os.path.join(managerDir, 'flows') flowFiles = [] for flowName in flowNames: flowFile = os.path.join(flowsDir, "%s.xml" % flowName) if not os.path.exists(flowFile): raise errors.FatalError, \ "Flow file %s does not exist" % flowFile flowFiles.append(flowFile) self.info("Loading flow %s" % flowFile) pid = getPid('manager', name) if pid: if checkPidRunning(pid): raise errors.FatalError, \ "Manager %s is already running (with pid %d)" % (name, pid) else: # there is a stale PID file, warn about it, remove it and # continue self.warning("Removing stale pid file %d for manager %s", pid, name) deletePidFile('manager', name) dirOptions = self._getDirOptions() command = "flumotion-manager %s -D --daemonize-to %s " \ "--service-name %s %s %s" % ( dirOptions, configure.daemondir, name, planetFile, " ".join(flowFiles)) self.debug("starting process %s" % command) retval = self.startProcess(command) if retval == 0: self.debug("Waiting for pid for manager %s" % name) pid = waitPidFile('manager', name) if pid: self.info("Started manager %s with pid %d" % (name, pid)) return True else: self.warning("manager %s could not start" % name) return False self.warning("manager %s could not start (return value %d)" % (name, retval)) return False