Exemple #1
0
    def stopWorker(self, name):
        """
        Stop the given worker if it is running.
        """
        self.info("Stopping worker %s" % name)
        pid = getPid('worker', name)
        if not pid:
            self.info("worker %s was not running" % name)
            return True

        # FIXME: ensure a correct process is running this pid
        if not checkPidRunning(pid):
            self.info("Worker %s is dead (stale pid %d), "
                      "cleaning up" % (name, pid))
            deletePidFile('worker', name)
            return False

        self.debug('Stopping worker %s with pid %d' % (name, pid))

        ret = self.stopProcess(pid)

        # we may need to remove the pid file ourselves, in case the process
        # failed to do it
        deletePidFile('worker', name, force=True)

        if ret:
            self.info('Stopped worker %s with pid %d' % (name, pid))
        return ret
Exemple #2
0
    def stopWorker(self, name):
        """
        Stop the given worker if it is running.
        """
        self.info("Stopping worker %s" % name)
        pid = getPid('worker', name)
        if not pid:
            self.info("worker %s was not running" % name)
            return True

        # FIXME: ensure a correct process is running this pid
        if not checkPidRunning(pid):
            self.info("Worker %s is dead (stale pid %d), "
                      "cleaning up" % (name, pid))
            deletePidFile('worker', name)
            return False

        self.debug('Stopping worker %s with pid %d' % (name, pid))

        ret = self.stopProcess(pid)

        # we may need to remove the pid file ourselves, in case the process
        # failed to do it
        deletePidFile('worker', name, force=True)

        if ret:
            self.info('Stopped worker %s with pid %d' % (name, pid))
        return ret
Exemple #3
0
def possess(daemonizeTo=None):
    fileutils.ensureDirExists(configure.logdir, "log file")
    fileutils.ensureDirExists(configure.rundir, "run file")
    if not daemonizeTo:
        daemonizeTo = '/'

    pid = process.getPid('transcoder-admin')
    if pid:
        if process.checkPidRunning(pid):
            raise iherrors.SystemError(
                'A flumotion-transcoder-admin is already running '
                + 'as pid %d' % pid)
        else:
            log.warning("flumotion-transcoder-admin should have been "
                        "running with pid %s.  Restarting", str(pid))
            process.deletePidFile('transcoder-admin')

    logPath = os.path.join(configure.logdir, 'transcoder-admin.log')

    # here we daemonize; so we also change our pid
    if not daemonizeTo:
        daemonizeTo = '/'
    process.daemonize(stdout=logPath, stderr=logPath,
                      directory=daemonizeTo)

    log.info('Started daemon')

    # from now on I should keep running, whatever happens
    log.debug('writing pid file')
    process.writePidFile('transcoder-admin')
Exemple #4
0
    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 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 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')
Exemple #7
0
    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
Exemple #8
0
    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
Exemple #9
0
 def clean(self, args):
     """
     Clean up dead process pid files as given in the args.
     """
     (managers, workers) = self._parseManagersWorkers("clean", args)
     self.debug("Clean managers %r and workers %r" % (managers, workers))
     for kind, names in [("manager", managers), ("worker", workers)]:
         for name in names:
             pid = getPid(kind, name)
             if not pid:
                 # may be a file that contains bogus data
                 try:
                     deletePidFile(kind, name)
                     print "deleted bogus pid file for %s %s" % (kind, name)
                 except OSError:
                     print ("failed to delete pid file for %s %s " "- ignoring" % (kind, name))
                 continue
             if not checkPidRunning(pid):
                 self.debug("Cleaning up stale pid %d for %s %s" % (pid, kind, name))
                 print "deleting stale pid file for %s %s" % (kind, name)
                 deletePidFile(kind, name)
Exemple #10
0
 def clean(self, args):
     """
     Clean up dead process pid files as given in the args.
     """
     (managers, workers) = self._parseManagersWorkers('clean', args)
     self.debug("Clean managers %r and workers %r" % (managers, workers))
     for kind, names in [('manager', managers), ('worker', workers)]:
         for name in names:
             pid = getPid(kind, name)
             if not pid:
                 # may be a file that contains bogus data
                 try:
                     deletePidFile(kind, name)
                     print "deleted bogus pid file for %s %s" % (kind, name)
                 except OSError:
                     print(
                         "failed to delete pid file for %s %s "
                         "- ignoring" % (kind, name))
                 continue
             if not checkPidRunning(pid):
                 self.debug("Cleaning up stale pid %d for %s %s" %
                            (pid, kind, name))
                 print "deleting stale pid file for %s %s" % (kind, name)
                 deletePidFile(kind, name)
Exemple #11
0
    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
Exemple #12
0
def exorcize():
    log.debug('deleting pid file')
    process.deletePidFile('transcoder-admin')