def _start_threadpool(self): self.logger.info("Init Threadpool") try: minthreads = self.config.getint('performance', 'minthreads') maxthreads = self.config.getint('performance', 'maxthreads') except configparser.NoSectionError: self.logger.warning( 'Performance section not configured, using default thread numbers' ) minthreads = 1 maxthreads = 3 queuesize = maxthreads * 10 return ThreadPool(minthreads, maxthreads, queuesize)
def reload(self): """apply config changes""" self.logger.info('Applying configuration changes...') # threadpool changes? if self.config.get( 'performance', 'backend') == 'thread' and self.threadpool is not None: minthreads = self.config.getint('performance', 'minthreads') maxthreads = self.config.getint('performance', 'maxthreads') if self.threadpool.minthreads != minthreads or self.threadpool.maxthreads != maxthreads: self.logger.info( 'Threadpool config changed, initialising new threadpool') queuesize = maxthreads * 10 currentthreadpool = self.threadpool self.threadpool = ThreadPool(minthreads, maxthreads, queuesize) currentthreadpool.stayalive = False # smtp engine changes? ports = self.config.get('main', 'incomingport') portspeclist = ports.split(',') portlist = [] for portspec in portspeclist: if portspec.find(':') > 0: (protocol, port) = portspec.split(':') port = int(port) else: port = int(portspec) portlist.append(port) alreadyRunning = False for serv in self.servers: if serv.port == port: alreadyRunning = True break if not alreadyRunning: self.start_connector(portspec) servercopy = self.servers[:] for serv in servercopy: if serv.port not in portlist: self.logger.info('Closing server socket on port %s' % serv.port) serv.shutdown() self.servers.remove(serv) self.logger.info('Config changes applied')
def startup(self): self.load_extensions() ok = self.load_plugins() if not ok: sys.stderr.write( "Some plugins failed to load, please check the logs. Aborting.\n" ) self.logger.info('Fuglu shut down after fatal error condition') sys.exit(1) self.logger.info("Init Stat Engine") self.statsthread = StatsThread(self.config) mrtg_stats_thread = threading.Thread( name='MRTG-Statswriter', target=self.statsthread.writestats, args=()) mrtg_stats_thread.daemon = True mrtg_stats_thread.start() self.logger.info("Init Threadpool") try: minthreads = self.config.getint('performance', 'minthreads') maxthreads = self.config.getint('performance', 'maxthreads') except configparser.NoSectionError: self.logger.warning( 'Performance section not configured, using default thread numbers' ) minthreads = 1 maxthreads = 3 queuesize = maxthreads * 10 self.threadpool = ThreadPool(minthreads, maxthreads, queuesize) self.logger.info("Starting interface sockets...") ports = self.config.get('main', 'incomingport') for port in ports.split(','): self.start_connector(port) # control socket control = ControlServer(self, address=self.config.get('main', 'bindaddress'), port=self.config.get('main', 'controlport')) ctrl_server_thread = threading.Thread(name='Control server', target=control.serve, args=()) ctrl_server_thread.daemon = True ctrl_server_thread.start() self.controlserver = control self.logger.info('Startup complete') if self.debugconsole: self.run_debugconsole() else: if self.config.getboolean('main', 'versioncheck'): # log possible issues with this version check_version_status() # mainthread dummy loop while self.stayalive: try: time.sleep(1) except KeyboardInterrupt: self.stayalive = False self.shutdown()