Пример #1
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()
Пример #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')
Пример #3
0
                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())

    try:
        agentProcess = AgentProcess()
Пример #4
0
 def helpInfo(self):
     kkbLib.printout("usage: %s install|start|stop|restart|check|help" % sys.argv[0])
Пример #5
0
            sys.stderr.write(message)
        else:
            message = "The process has been run, the process id:%d\n"
            sys.stderr.write(message % pid)

    def helpInfo(self):
        kkbLib.printout("usage: %s install|start|stop|restart|check|help" % sys.argv[0])


if __name__ == "__main__":
    pname = 'KKB Monitor Master'
    setproctitle(pname)
    logfile = kkbLib.getPath() + 'log/' + kkbLib.date(time.time(), format='%Y-%m-%d') + '.log'
    Contr = Control(stderr=logfile, stdout=logfile)
    if len(sys.argv) == 2:
        if 'start' == sys.argv[1]:
            Contr.start()
        elif 'stop' == sys.argv[1]:
            Contr.stop()
        elif 'restart' == sys.argv[1]:
            Contr.restart()
        elif 'check' == sys.argv[1]:
            Contr.check()
        elif 'help' == sys.argv[1]:
            Contr.helpInfo()
        else:
            kkbLib.printout("未知命令")
            sys.exit(2)
    else:
        kkbLib.printout("usage: %s start|stop|restart|check|help" % sys.argv[0])
        sys.exit(2)