Esempio n. 1
0
    def __init__(self):
        self.clients = [ ]   # all clients
        self.clientcount = 0
        self.anonymouscount = 1
        self.announcecount = 0
        
            # clients separated into their separate categories
        self.connectedclients = [ ]   # what a client first appears in before any further information has come to identify what it is
        self.umlmonitoringclients = [ ]
        self.draftscraperclients = [ ]
        self.rpcrunningclients = [ ]
        self.stimulate_runclients = [ ]
        self.httpgetclients = [ ]

            # tables for quick access
        self.scheduledrunners = { } # maps from short_name to client objects (that are also put into guidclientmap)
        self.guidclientmap = { }  # maps from short_name to EditorsOnOneScraper objects
        self.runidclientmap = { } # maps runid to the client controlling the running

        # Get these settings from config 
        try:
            max_count      = config.getint("twister", "max_scheduled")            
            schedule_check = config.getint("twister", "schedule_check_seconds")                        
        except:
            max_count      = 10
            schedule_check = 30


        self.maxscheduledscrapers = max_count
        self.notifiedmaxscheduledscrapers = self.maxscheduledscrapers

        # set the visible heartbeat going which is used to call back and look up the schedulers
        self.lc = task.LoopingCall(self.requestoverduescrapers)
        self.lc.start(schedule_check)
Esempio n. 2
0
def main():
    # daemon mode
    if os.fork() == 0 :
        os.setsid()
        sys.stdin = open('/dev/null')
        if stdoutlog:
            sys.stdout = stdoutlog
            sys.stderr = stdoutlog
        if os.fork() == 0:
            ppid = os.getppid()
            while ppid != 1:
                time.sleep(1)
                ppid = os.getppid()
        else:
            os._exit(0)
    else:
        os.wait()
        sys.exit(1)

    pf = open(poptions.pidfile, 'w')
    pf.write('%d\n' % os.getpid())
    pf.close()

    if poptions.setuid:
        gid = grp.getgrnam("nogroup").gr_gid
        os.setregid(gid, gid)
        uid = pwd.getpwnam("nobody").pw_uid
        os.setreuid(uid, uid)

    logging.config.fileConfig(poptions.config)

    #  subproc mode
    signal.signal(signal.SIGTERM, sigTerm)
    while True:
        child = os.fork()
        if child == 0 :
            time.sleep (1)
            break

        sys.stdout.write("Forked subprocess: %d\n" % child)
        sys.stdout.flush()

        os.wait()


    # http://localhost:9010/update?runid=1234&message={'sources':'somejson}
    runnerfactory = RunnerFactory()
    port = config.getint('twister', 'port')
    reactor.listenTCP(port, runnerfactory)
    logger.info("Twister listening on port %d" % port)
    reactor.run()   # this function never returns