Exemplo n.º 1
0
    def check(self):
        try:
            pid = kkbLib.readPid('master')
        except IOError:
            pid = None

        if not pid:
            message = "Process has closed\n"
            sys.stderr.write(message)
        else:
            message = "The process has been run, the process id:%d\n"
            sys.stderr.write(message % pid)
Exemplo n.º 2
0
    def stop(self):
        # Get the pid from the pidfile
        try:
            pid = kkbLib.readPid('master')
        except IOError:
            pid = None

        if not pid:
            message = "The process does not exist, the operation aborts"
            kkbLib.printout(message)
            kkbLib.info(message)
            return  # not an error in a restart
        # Try killing the daemon process
        try:
            while 1:
                os.kill(pid, SIGTERM)
                time.sleep(0.1)
        except OSError:
            kkbLib.rmPid('agent')
            kkbLib.rmPid('master')
        kkbLib.printout('Successful process closes')
        kkbLib.info('Successful process closes')
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
                    self.agentProcess.restart()

                if line == 'ping\n':
                    self.masterMonitor.heartbeat()
                    continue

            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: