예제 #1
0
def startWeb(p, resourcePath, nonesym, timec, timebg, btc, btbg, etc, etbg,
             showetflag, showbtflag):
    global port, process, static_path, nonesymbol, timecolor, timebackground, btcolor, btbackground, etcolor, etbackground, showet, showbt
    try:
        port = p
        static_path = resourcePath
        nonesymbol = nonesym
        timecolor = timec
        timebackground = timebg
        btcolor = btc
        btbackground = btbg
        etcolor = etc
        etbackground = etbg
        showet = showetflag
        showbt = showbtflag
        if psystem() != 'Windows':
            gsignal(SIGQUIT, kill)

        # start the server in a separate process


# using multiprocessing
        process = mProcess(target=work,
                           args=(
                               port,
                               resourcePath,
                               nonesym,
                               timec,
                               timebg,
                               btc,
                               btbg,
                               etc,
                               etbg,
                               showetflag,
                               showbtflag,
                           ))
        process.start()

        libtime.sleep(4)

        # check successful start
        url = "http://127.0.0.1:" + str(port) + "/status"
        r = rget(url, timeout=2)

        if r.status_code == 200:
            return True
        else:
            return False

    except Exception:
        #        import traceback
        #        import sys
        #        traceback.print_exc(file=sys.stdout)
        return False
예제 #2
0
def startWeb(p,resourcePath,nonesym,timec,timebg,btc,btbg,etc,etbg,showetflag,showbtflag):
    global port, process, static_path, nonesymbol, timecolor, timebackground, btcolor, btbackground, etcolor, etbackground, showet, showbt
    try:
        port = p
        static_path = resourcePath
        nonesymbol = nonesym
        timecolor = timec
        timebackground = timebg
        btcolor = btc
        btbackground = btbg
        etcolor = etc
        etbackground = etbg
        showet = showetflag
        showbt = showbtflag
        if psystem() != 'Windows':
            gsignal(SIGQUIT, kill)
        
        # start the server in a separate process
# using multiprocessing
        process = mProcess(target=work,args=(
            port,
            resourcePath,
            nonesym,
            timec,
            timebg,
            btc,
            btbg,
            etc,
            etbg,
            showetflag,
            showbtflag,))
        process.start()
       
        libtime.sleep(4)
        
        # check successful start
        url = "http://127.0.0.1:" + str(port) + "/status"
        r = rget(url,timeout=2)
        
        if r.status_code == 200:
            return True
        else:
            return False

    except Exception:
#        import traceback
#        import sys
#        traceback.print_exc(file=sys.stdout)
        return False
    def start_workers(self):
        """ start worker processes """

        # setter config
        setter_conf = {}
        for attr in [
                "analyze_move", "analyze_stale", "analyze_offsubnet",
                "auto_clear_stale", "auto_clear_offsubnet",
                "notify_stale_syslog", "notify_stale_email",
                "notify_offsubnet_syslog", "notify_offsubnet_email",
                "notify_move_syslog", "notify_move_email", "notify_email",
                "notify_syslog", "notify_syslog_port", "max_ep_events",
                "worker_hello", "worker_hello_multiplier",
                "trust_subscription", "queue_interval",
                "transitory_delete_time", "transitory_stale_time",
                "transitory_xr_stale_time", "transitory_offsubnet_time",
                "monitor_disable"
        ]:
            if hasattr(self, attr): setter_conf[attr] = getattr(self, attr)

        # manually stop any/all workers before starting workers
        self.stop_workers()
        self.all_workers = []
        self.workers = {}
        for wid in range(self.max_workers):
            logger.debug("starting worker id(%s)" % wid)
            w = {
                "wid": wid,
                "txQ": mQueue(),
                "rxQ": mQueue(),
                "prQ": mQueue(),
                "last_hello": 0
            }
            p = mProcess(
                target=start_ep_worker,
                kwargs={
                    "wid": w["wid"],
                    "txQ":
                    w["rxQ"],  # swap tx/rx queue from worker perspective
                    "rxQ": w["txQ"],
                    "prQ": w["prQ"],
                    "fabric": self.fabric,
                    "overlay_vnid": self.overlay_vnid
                })
            w["process"] = p
            # enqueue any specific variables for this worker via job
            w["txQ"].put(EPJob("setter", {}, data=setter_conf))
            p.start()
            self.workers[wid] = w
            self.all_workers.append(w)

        # setup/start watch worker
        if not self.wworker_disable:
            logger.debug("starting watcher worker")
            self.wworker = {
                "wid": "watcher",
                "txQ": mQueue(),
                "rxQ": mQueue(),
                "prQ": mQueue(),
                "last_hello": 0
            }
            p = mProcess(
                target=start_ep_worker,
                kwargs={
                    "wid": self.wworker["wid"],
                    "txQ": self.wworker["rxQ"],  # swap tx/rx queue
                    "rxQ": self.wworker["txQ"],
                    "prQ": self.wworker["prQ"],
                    "fabric": self.fabric,
                    "overlay_vnid": self.overlay_vnid
                })
            self.wworker["process"] = p
            self.wworker["txQ"].put(EPJob("setter", {}, data=setter_conf))
            p.start()
            self.all_workers.append(self.wworker)
        else:
            logger.debug("skipping watch worker")

        if self.pworker_disable:
            logger.debug("skipping priority worker")
            return

        # setup/start priority queue worker
        logger.debug("starting priority worker")
        bcastQ = []
        bcastPrQ = []
        for wid in self.workers:
            bcastQ.append(self.workers[wid]["txQ"])
            bcastPrQ.append(self.workers[wid]["prQ"])
        if not self.wworker_disable:
            bcastQ.append(self.wworker["txQ"])
            bcastPrQ.append(self.wworker["prQ"])
        self.pworker = {
            "wid": "pri",
            "txQ": mQueue(),
            "rxQ": mQueue(),
            "prQ": mQueue(),
            "last_hello": 0
        }
        p = mProcess(
            target=start_ep_priority_worker,
            kwargs={
                "wid": self.pworker["wid"],
                "txQ": self.pworker["rxQ"],  # swap tx/rq queue 
                "rxQ": self.pworker["txQ"],
                "prQ": self.pworker["prQ"],
                "bcastQ": bcastQ,
                "bcastPrQ": bcastPrQ,
                "fabric": self.fabric,
            })
        self.pworker["txQ"].put(EPJob("setter", {}, data=setter_conf))
        self.pworker["txQ"].put(EPJob("init", {}))
        self.pworker["process"] = p
        p.start()
        self.all_workers.append(self.pworker)

        # wait for priority worker setter and init job to successfully complete
        job = None
        try:
            job_setter = self.pworker["rxQ"].get(True, 3.0)
            job = self.pworker["rxQ"].get(True, 3.0)
        except Empty:
            pass
        if job is None or "success" not in job.key or not job.key["success"]:
            err = "failed to initialize priority worker"
            if job is not None and "error" in job.key: err = job.key["error"]
            logger.warn(err)
            self.stop_workers()
            raise Exception(err)
        else:
            logger.debug("successfully initialized priority worker")