def start(self): """ Start the daemon """ # Check for a pidfile to see if the daemon already runs try: pid = kkbLib.readPid('master') except IOError: pid = 0 if pid > 0: isRun = kkbLib.checkPidLinux(pid) if isRun: kkbLib.printout('Program has been started, the process ID:' + str(pid)) sys.exit(1) # Start the daemon kkbLib.info('starting daemon...') self._daemonize() kkbLib.info('started daemon.') kkbLib.info('starting run...') self._run()
except Exception: kkbLib.error(traceback.format_exc()) if __name__ == "__main__": pname = 'KKB Monitor Agent' setproctitle(pname) agentPid = os.getpid() try: pid = kkbLib.readPid('agent') except IOError: pid = 0 if pid > 0: isRun = kkbLib.checkPidLinux(pid) if isRun: kkbLib.printout('Program has been started, the process PID:' + str(pid)) sys.exit(1) kkbLib.writePid(agentPid, 'agent') kkbLib.info('Starting agent process') kkbLib.printout('Starting agent process') parentPid = None try: if len(sys.argv) > 1: parentPid = sys.argv[1] except Exception: kkbLib.error(traceback.format_exc())