コード例 #1
0
ファイル: test_arbiter.py プロジェクト: unkcpz/circus
    def test_start_with_callback(self):
        controller = "tcp://127.0.0.1:%d" % get_available_port()
        sub = "tcp://127.0.0.1:%d" % get_available_port()
        arbiter = Arbiter([], controller, sub, check_delay=-1)

        callee = mock.MagicMock()

        def callback(*args):
            callee()
            arbiter.stop()

        arbiter.start(cb=callback)

        self.assertEqual(callee.call_count, 1)
コード例 #2
0
ファイル: test_arbiter.py プロジェクト: aubustou/circus
    def test_start_with_callback(self):
        controller = "tcp://127.0.0.1:%d" % get_available_port()
        sub = "tcp://127.0.0.1:%d" % get_available_port()
        arbiter = Arbiter([], controller, sub, check_delay=-1)

        callee = mock.MagicMock()

        def callback(*args):
            callee()
            arbiter.stop()

        arbiter.start(cb=callback)

        self.assertEqual(callee.call_count, 1)
コード例 #3
0
ファイル: test_arbiter.py プロジェクト: aubustou/circus
 def test_start_arbiter_with_autostart(self):
     arbiter = Arbiter([], DEFAULT_ENDPOINT_DEALER, DEFAULT_ENDPOINT_SUB,
                       loop=get_ioloop(),
                       check_delay=-1)
     arbiter.add_watcher('foo', SLEEP % 5, autostart=False)
     try:
         yield arbiter.start()
         self.assertEqual(arbiter.watchers[0].status(), 'stopped')
     finally:
         yield arbiter.stop()
コード例 #4
0
ファイル: test_arbiter.py プロジェクト: bbinet/circus
 def test_start_arbiter_with_autostart(self):
     arbiter = Arbiter([], DEFAULT_ENDPOINT_DEALER, DEFAULT_ENDPOINT_SUB,
                       loop=tornado.ioloop.IOLoop.instance(),
                       check_delay=-1)
     arbiter.add_watcher('foo', 'sleep 5', autostart=False)
     try:
         yield arbiter.start()
         self.assertEqual(arbiter.watchers[0].status(), 'stopped')
     finally:
         yield arbiter.stop()
コード例 #5
0
 def test_start_arbiter_with_autostart(self):
     arbiter = Arbiter([], DEFAULT_ENDPOINT_DEALER, DEFAULT_ENDPOINT_SUB,
                       loop=get_ioloop(),
                       check_delay=-1)
     arbiter.add_watcher('foo', SLEEP % 5, autostart=False)
     try:
         yield arbiter.start()
         self.assertEqual(arbiter.watchers[0].status(), 'stopped')
     finally:
         yield arbiter.stop()
コード例 #6
0
ファイル: test_arbiter.py プロジェクト: aubustou/circus
 def test_add_watcher(self):
     controller = "tcp://127.0.0.1:%d" % get_available_port()
     sub = "tcp://127.0.0.1:%d" % get_available_port()
     arbiter = Arbiter([], controller, sub, loop=get_ioloop(),
                       check_delay=-1)
     arbiter.add_watcher('foo', SLEEP % 5)
     try:
         yield arbiter.start()
         self.assertEqual(arbiter.watchers[0].status(), 'active')
     finally:
         yield arbiter.stop()
コード例 #7
0
ファイル: test_arbiter.py プロジェクト: bbinet/circus
 def test_circushttpd(self):
     arbiter = Arbiter([], DEFAULT_ENDPOINT_DEALER, DEFAULT_ENDPOINT_SUB,
                       loop=tornado.ioloop.IOLoop.instance(),
                       check_delay=-1, httpd=True, debug=True)
     self.arbiters.append(arbiter)
     try:
         yield arbiter.start()
         poll_for_callable(self.assertDictEqual,
                           arbiter.statuses, {'circushttpd': 'active'})
     finally:
         yield arbiter.stop()
コード例 #8
0
 def test_add_watcher(self):
     controller = "tcp://127.0.0.1:%d" % get_available_port()
     sub = "tcp://127.0.0.1:%d" % get_available_port()
     arbiter = Arbiter([], controller, sub, loop=get_ioloop(),
                       check_delay=-1)
     arbiter.add_watcher('foo', SLEEP % 5)
     try:
         yield arbiter.start()
         self.assertEqual(arbiter.watchers[0].status(), 'active')
     finally:
         yield arbiter.stop()
コード例 #9
0
ファイル: test_arbiter.py プロジェクト: cdgz/circus
 def test_add_watcher(self):
     arbiter = Arbiter([],
                       DEFAULT_ENDPOINT_DEALER,
                       DEFAULT_ENDPOINT_SUB,
                       loop=tornado.ioloop.IOLoop.instance(),
                       check_delay=-1)
     arbiter.add_watcher('foo', 'sleep 5')
     try:
         yield arbiter.start()
         self.assertEqual(arbiter.watchers[0].status(), 'active')
     finally:
         yield arbiter.stop()
コード例 #10
0
ファイル: test_arbiter.py プロジェクト: aubustou/circus
    def test_circushttpd(self):
        controller = "tcp://127.0.0.1:%d" % get_available_port()
        sub = "tcp://127.0.0.1:%d" % get_available_port()

        arbiter = Arbiter([], controller, sub, loop=get_ioloop(),
                          check_delay=-1, httpd=True, debug=True)
        self.arbiters.append(arbiter)
        try:
            yield arbiter.start()
            poll_for_callable(self.assertDictEqual,
                              arbiter.statuses, {'circushttpd': 'active'})
        finally:
            yield arbiter.stop()
コード例 #11
0
    def test_circushttpd(self):
        controller = "tcp://127.0.0.1:%d" % get_available_port()
        sub = "tcp://127.0.0.1:%d" % get_available_port()

        arbiter = Arbiter([], controller, sub, loop=get_ioloop(),
                          check_delay=-1, httpd=True, debug=True)
        self.arbiters.append(arbiter)
        try:
            yield arbiter.start()
            poll_for_callable(self.assertDictEqual,
                              arbiter.statuses, {'circushttpd': 'active'})
        finally:
            yield arbiter.stop()
コード例 #12
0
ファイル: test_arbiter.py プロジェクト: aubustou/circus
    def test_start_with_callback_and_given_loop(self):
        controller = "tcp://127.0.0.1:%d" % get_available_port()
        sub = "tcp://127.0.0.1:%d" % get_available_port()
        arbiter = Arbiter([], controller, sub, check_delay=-1,
                          loop=get_ioloop())

        callback = mock.MagicMock()

        try:
            yield arbiter.start(cb=callback)
        finally:
            yield arbiter.stop()

        self.assertEqual(callback.call_count, 0)
コード例 #13
0
    def test_start_with_callback_and_given_loop(self):
        controller = "tcp://127.0.0.1:%d" % get_available_port()
        sub = "tcp://127.0.0.1:%d" % get_available_port()
        arbiter = Arbiter([], controller, sub, check_delay=-1,
                          loop=get_ioloop())

        callback = mock.MagicMock()

        try:
            yield arbiter.start(cb=callback)
        finally:
            yield arbiter.stop()

        self.assertEqual(callback.call_count, 0)
コード例 #14
0
ファイル: test_arbiter.py プロジェクト: cdgz/circus
 def test_circushttpd(self):
     arbiter = Arbiter([],
                       DEFAULT_ENDPOINT_DEALER,
                       DEFAULT_ENDPOINT_SUB,
                       loop=tornado.ioloop.IOLoop.instance(),
                       check_delay=-1,
                       httpd=True,
                       debug=True)
     self.arbiters.append(arbiter)
     try:
         yield arbiter.start()
         poll_for_callable(self.assertDictEqual, arbiter.statuses,
                           {'circushttpd': 'active'})
     finally:
         yield arbiter.stop()
コード例 #15
0
ファイル: circusd.py プロジェクト: sakti/circus
                    limit = cfg_name[7:]
                    rlimits[limit] = int(cfg_value)

            watcher = Watcher(name, cmd, numprocesses=numprocesses,
                        warmup_delay=warmup_delay, working_dir=working_dir,
                        shell=shell, uid=uid, gid=gid, send_hup=send_hup,
                        times=times, within=within, retry_in=retry_in,
                        max_retry=max_retry, graceful_timeout=graceful_timeout,
                        rlimits=rlimits)

            watchers.append(watcher)

    # main circus options
    check = cfg.dget('circus', 'check_delay', 5, int)
    endpoint = cfg.dget('circus', 'endpoint', 'tcp://127.0.0.1:5555')
    pubsub_endpoint = cfg.dget('circus', 'pubsub_endpoint',
            'tcp://127.0.0.1:5556')

    arbiter = Arbiter(watchers, endpoint, pubsub_endpoint, check)
    try:
        arbiter.start()
    finally:
        arbiter.stop()
        if pidfile is not None:
            pidfile.unlink()

    sys.exit(0)

if __name__ == '__main__':
    main()
コード例 #16
0
def main():
    #configure_logger(logger, 'DEBUG')
    config_mod = 'circus_settings'
    if len(sys.argv) > 1:
        config_mod = sys.argv[1]
    
    config = import_module(config_mod)
    
    
    for p in config.PATHS:
        ap = os.path.abspath(p)
        if ap not in os.sys.path:
            os.sys.path.append(ap)

    watchers = []
    sockets = []

    for s in config.SERVERS:
        
        w = Watcher(gc(s, SERVER_NAME), 
                    gc(s, SERVER_PROGRAM), 
                    gc(s, SERVER_ARGS),
                    numprocesses=gc(s, SERVER_WORKERS, 1), 
                    working_dir=gc(s, SERVER_WORKING_DIR, './'),
                    env=gc(s, SERVER_ENV, dict()),
                    copy_env=True, 
                    copy_path=True,
                    use_sockets=True)
        
        watchers.append(w)
        
        sock_port = gc(s, SERVER_PORT)
        if sock_port is not None:
            sock_name = gc(s, SERVER_NAME)
            sock_host = gc(s, SERVER_HOST, '127.0.0.1')
            sock = CircusSocket(sock_name, host=sock_host, port=sock_port)
            sockets.append(sock)
        
    for sock in sockets:
        print '>> %s'%(sock,)

    try:
        WANT_WEB = getattr(config, 'WANT_WEB')
    except Exception:
        WANT_WEB = True

    if HAS_WEB and WANT_WEB:
        arbiter = Arbiter(watchers, DEFAULT_ENDPOINT_DEALER, DEFAULT_ENDPOINT_SUB, 
                          sockets=sockets,
                        stats_endpoint=DEFAULT_ENDPOINT_STATS, 
                        multicast_endpoint=DEFAULT_ENDPOINT_MULTICAST, 
                        statsd=True, 
                        httpd=True,
                        httpd_port=9999)
    else:
        arbiter = Arbiter(watchers, DEFAULT_ENDPOINT_DEALER, DEFAULT_ENDPOINT_SUB,
                          sockets=sockets,
                        stats_endpoint=DEFAULT_ENDPOINT_STATS, 
                        multicast_endpoint=DEFAULT_ENDPOINT_MULTICAST)

    arbiter.start()