예제 #1
0
    def tearDown(self):
        tee = log.get_default()
        tee.remove_keeper("test-buffer")
        self.keeper.clean()
        try:
            os.remove(run.get_pidpath(os.path.curdir, "dummy_process"))
        except OSError:
            pass

        yield common.TestCase.tearDown(self)
예제 #2
0
파일: _noarch_run.py 프로젝트: f3at/feat
def acquire_pidfile(rundir, process_type=PROCESS_TYPE, name=None):
    """
    Open a PID file for writing, using the given process type and
    process name for the filename. The returned file can be then passed
    to writePidFile after forking.

    @rtype:   str
    @returns: file object, open for writing
    """
    from feat.common.run import get_pidpath
    _ensure_dir(rundir, "rundir")
    path = get_pidpath(rundir, process_type, name)
    return open(path, 'w')
예제 #3
0
파일: _noarch_run.py 프로젝트: f3at/feat
def delete_pidfile(rundir, process_type=PROCESS_TYPE, name=None, force=False):
    """
    Delete the pid file in the run directory, using the given process type
    and process name for the filename.

    @param force: if errors due to the file not existing should be ignored
    @type  force: bool

    @rtype:   str
    @returns: full path to the pid file that was written
    """
    from feat.common.run import get_pidpath
    log.debug(process_type, 'deleting pid file')
    path = get_pidpath(rundir, process_type, name)
    try:
        os.unlink(path)
    except OSError, e:
        if e.errno == errno.ENOENT and force:
            pass
        else:
            raise
예제 #4
0
파일: _noarch_run.py 프로젝트: f3at/feat
def write_pidfile(rundir, process_type=PROCESS_TYPE,
                  name=None, file=None): #@ReservedAssignment
    """
    Write a pid file in the run directory, using the given process type
    and process name for the filename.

    @rtype:   str
    @returns: full path to the pid file that was written
    """
    from feat.common.run import get_pidpath
    # don't shadow builtin file
    pid_file = file
    if pid_file is None:
        _ensure_dir(rundir, "rundir")
        filename = get_pidpath(rundir, process_type, name)
        pid_file = open(filename, 'w')
    else:
        filename = pid_file.name
    pid_file.write("%d\n" % (os.getpid(), ))
    pid_file.close()
    os.chmod(filename, 0644)
    return filename