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')
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')