コード例 #1
0
ファイル: init.py プロジェクト: nivertech/mrim
def start():
    if conf.psyco:
        try:
            import psyco
            psyco.full()
            logger.critical("Enabling psyco support.")
        except:
            logger.critical(
                "Looks like psyco is not installed in your system. Psyco acceleration will not be enabled."
            )
            pass
    if conf.http_proxy:
        try:
            conf.http_proxy = utils.get_proxy(conf.http_proxy)
        except:
            logger.critical(
                "Invalid format of HTTP-proxy. No proxy will be used.")
            conf.http_proxy = None
    logger.critical("Starting the caching resolver in a separate thread.")
    resolver.start(['mrim.mail.ru', 'avt.foto.mail.ru'])
    while 1:
        try:
            xmpp_con = transport.XMPPTransport(conf.name, conf.disconame,
                                               conf.server, conf.port,
                                               conf.passwd, logger)
            logger.critical("Connecting to XMPP server")
            xmpp_con.run()
        except KeyboardInterrupt:
            logger.critical('Got SIGINT, closing connections')
            xmpp_con.stop()
            try:
                os.unlink(conf.pidfile)
            except OSError:
                pass
            logger.critical('Shutdown')
            break
        except:
            traceback.print_exc()
            logger.critical("Connection to server lost")
            logger.critical("Trying to reconnect over 5 seconds")
            try:
                xmpp_con.stop(notify=False)
                del xmpp_con
            except:
                traceback.print_exc()
                pass
            time.sleep(5)
コード例 #2
0
ファイル: init.py プロジェクト: zinid/mrim
def start():
    if conf.psyco:
        try:
            import psyco

            psyco.full()
            logger.critical("Enabling psyco support.")
        except:
            logger.critical("Looks like psyco is not installed in your system. Psyco acceleration will not be enabled.")
            pass
    if conf.http_proxy:
        try:
            conf.http_proxy = utils.get_proxy(conf.http_proxy)
        except:
            logger.critical("Invalid format of HTTP-proxy. No proxy will be used.")
            conf.http_proxy = None
    logger.critical("Starting the caching resolver in a separate thread.")
    resolver.start(["mrim.mail.ru", "avt.foto.mail.ru"])
    while 1:
        try:
            xmpp_con = transport.XMPPTransport(conf.name, conf.disconame, conf.server, conf.port, conf.passwd, logger)
            logger.critical("Connecting to XMPP server")
            xmpp_con.run()
        except KeyboardInterrupt:
            logger.critical("Got SIGINT, closing connections")
            xmpp_con.stop()
            try:
                os.unlink(conf.pidfile)
            except OSError:
                pass
            logger.critical("Shutdown")
            break
        except:
            traceback.print_exc()
            logger.critical("Connection to server lost")
            logger.critical("Trying to reconnect over 5 seconds")
            try:
                xmpp_con.stop(notify=False)
                del xmpp_con
            except:
                traceback.print_exc()
                pass
            time.sleep(5)
コード例 #3
0
ファイル: client.py プロジェクト: dgvncsz0f/pong
    if (t1 - t0 >= 1):
        for k in sorted(c.keys()):
            print("%s [%d]" % (k, c[k]))
        print("--")
        return({}, t1)
    return(c, t0)

def client (servers):
    c  = {}
    t0 = time.time()
    for s in servers:
        if (s is None):
            k = "error"
        else:
            k = pingk(s)
        c[k] = c.get(k, 0) + 1
        c, t0 = dump(c, t0)

def usage (p):
    print("use: %s consul ip|remote" % p)
            
if (len(sys.argv) >= 2):
    if (sys.argv[1] == "consul"):
        resolver.start(sys.argv[2])
        client(resolver.rr())
    else:
        client(repeat((sys.argv[1], int(sys.argv[2], 10))))

else:
    usage(sys.argv[0])
コード例 #4
0
ファイル: haproxy.py プロジェクト: dgvncsz0f/pong
            return(o_md5 != n_md5)
    except:
        return(True)

def haproxy_reload ():
    try:
        with open(HAPROXY_PID, "r") as fh:
            pid = fh.read()
    except:
        pid = ""
    if (len(pid) > 0):
        print("reloading haproxy")
        os.system("haproxy -f %s -st %s" % (HAPROXY_CFG, pid))
    else:
        print("starting haproxy")
        os.system("haproxy -f %s" % (HAPROXY_CFG,))
    
def haproxy ():
    cfg = haproxy_cfg()
    if (haproxy_requires_reload(cfg)):
        with open(HAPROXY_CFG, "w") as fh:
            fh.write(cfg)
        haproxy_reload()

resolver.start(CONSUL)
while True:
    try:
        haproxy()
    except: pass
    time.sleep(5)