def start_ccnet_session(self): '''Connect to ccnet-server, retry util connection is made''' self._ccnet_session = AsyncClient(self._ccnet_dir, self._evbase, central_config_dir=self._central_config_dir) connector = ClientConnector(self._ccnet_session) connector.connect_daemon_with_retry() self._sync_client = ccnet.SyncClient(self._ccnet_dir, central_config_dir=self._central_config_dir) self._sync_client.connect_daemon()
def create_ccnet_session(ccnet_dir, evbase): # create ccnet async client ccnet_session = AsyncClient(ccnet_dir, evbase) try: # connect to ccnet server ccnet_session.connect_daemon() logging.info('connected to ccnet server') return ccnet_session except ccnet.NetworkError: logging.error('can not connect to ccnet server, exit') sys.exit()
def main(): init_logging() evbase = libevent.Base() session = AsyncClient(CCNET_CONF_DIR, evbase) session.connect_daemon() register_rpc_functions(session) session.main_loop()
class App(object): def __init__(self, ccnet_dir, args, events_listener_enabled=True, background_tasks_enabled=True): self._ccnet_dir = ccnet_dir self._central_config_dir = os.environ.get('SEAFILE_CENTRAL_CONF_DIR') self._args = args self._events_listener_enabled = events_listener_enabled self._bg_tasks_enabled = background_tasks_enabled try: load_config(args.config_file) except Exception as e: logging.error('Error loading seafevents config. Detial: %s' % e) raise RuntimeError("Error loading seafevents config. Detial: %s" % e) self._events_listener = None if self._events_listener_enabled: self._events_listener = EventsMQListener(self._args.config_file) if appconfig.publish_enabled: events_publisher.init() else: logging.info("Events publish to redis is disabled.") self._bg_tasks = None if self._bg_tasks_enabled: self._bg_tasks = BackgroundTasks(args.config_file) if appconfig.enable_statistics: self.update_login_record_task = CountUserActivity() self.count_traffic_task = CountTrafficInfo() self._ccnet_session = None self._sync_client = None self._evbase = libevent.Base() #pylint: disable=E1101 self._sighandler = SignalHandler(self._evbase) def start_ccnet_session(self): '''Connect to ccnet-server, retry util connection is made''' self._ccnet_session = AsyncClient(self._ccnet_dir, self._evbase, central_config_dir=self._central_config_dir) connector = ClientConnector(self._ccnet_session) connector.connect_daemon_with_retry() self._sync_client = ccnet.SyncClient(self._ccnet_dir, central_config_dir=self._central_config_dir) self._sync_client.connect_daemon() def connect_ccnet(self): self.start_ccnet_session() if self._events_listener: try: self._sync_client.register_service_sync('seafevents-events-dummy-service', 'rpc-inner') except: logging.exception('Another instance is already running') do_exit(1) self._events_listener.start(self._ccnet_session) if self._bg_tasks: self._bg_tasks.on_ccnet_connected(self._ccnet_session, self._sync_client) def _serve(self): try: self._ccnet_session.main_loop() except ccnet.NetworkError: logging.warning('connection to ccnet-server is lost') if self._args.reconnect: self.connect_ccnet() else: do_exit(0) except Exception: logging.exception('Error in main_loop:') do_exit(0) def serve_forever(self): self.connect_ccnet() if self._bg_tasks: self._bg_tasks.start(self._evbase) else: logging.info("Background task is disabled.") if appconfig.enable_statistics: self.update_login_record_task.start() self.count_traffic_task.start() else: logging.info("User login statistics is disabled.") logging.info("Traffic statistics is disabled.") while True: self._serve()
def main(): init_logging() session = AsyncClient(CCNET_CONF_DIR) session.connect_daemon() register_rpc_functions(session) session.main_loop()
class App(object): def __init__(self, ccnet_dir, args, events_listener_enabled=True): self._ccnet_dir = ccnet_dir self._central_config_dir = os.environ.get('SEAFILE_CENTRAL_CONF_DIR') self._args = args self._events_listener_enabled = events_listener_enabled try: load_config(args.config_file) except Exception as e: logging.error('Error loading seafevents config. Detial: %s' % e) raise RuntimeError("Error loading seafevents config. Detial: %s" % e) self._events_listener = None if self._events_listener_enabled: self._events_listener = EventsMQListener(self._args.config_file) self._ccnet_session = None self._sync_client = None self._evbase = libevent.Base() #pylint: disable=E1101 self._sighandler = SignalHandler(self._evbase) def start_ccnet_session(self): '''Connect to ccnet-server, retry util connection is made''' self._ccnet_session = AsyncClient( self._ccnet_dir, self._evbase, central_config_dir=self._central_config_dir) connector = ClientConnector(self._ccnet_session) connector.connect_daemon_with_retry() self._sync_client = ccnet.SyncClient( self._ccnet_dir, central_config_dir=self._central_config_dir) self._sync_client.connect_daemon() def connect_ccnet(self): self.start_ccnet_session() if self._events_listener: try: self._sync_client.register_service_sync( 'seafevents-events-dummy-service', 'rpc-inner') except: logging.exception('Another instance is already running') do_exit(1) self._events_listener.start(self._ccnet_session) def _serve(self): try: self._ccnet_session.main_loop() except ccnet.NetworkError: logging.warning('connection to ccnet-server is lost') if self._args.reconnect: self.connect_ccnet() else: do_exit(0) except Exception: logging.exception('Error in main_loop:') do_exit(0) def serve_forever(self): self.connect_ccnet() while True: self._serve()