def handle_sigusr1(self, signum, frame): """Handle signal SIGUSR1 to reload server configuration""" logging.info('reload server configuration (by signal)') # Catch exception in the I{main} method caused by received signal self.__by_signal_do = 1 config = get_conf(CFG_PATH) # PID file cannot be changed config['server']['pid'] = self._config['server']['pid'] # Log file path changed if self._config['server']['log'] != config['server']['log']: logging.close(0) logging.init(0, filename=config['server']['log']) # Local socket path changed init_loc = (config['server']['sock'] != self._config['server']['sock']) # SSL option changed and/or server ip/port, we need to # shutdown current socket and open new one init_srv = (config['ssl'] != self._config['ssl'] \ or config['server']['port'] != self._config['server']['port'] \ or config['server']['ip'] != self._config['server']['ip']) self._config = config.copy() if init_srv: try: self.socket.shutdown(socket.SHUT_RDWR) self._create_bind_activate(1) except Exception as e: # @todo: fix: if cannot bind new socket, do not reload config self.__by_signal_do = 0 logging.error(e) if init_loc: try: self._create_local_socket(1) except Exception as e: pass self.socket.settimeout(config['server']['timeout']) # Non-blocking mode self.__local_sock.settimeout(0.0) logging.info('server configuration reloaded') del config
def clean_on_exit(fp_sock): """Method executed on process exit""" logging.info('clean up on process exit') try: os.remove(fp_sock) except: pass logging.info('shutdown logging system') logging.close() if len(sys.argv) <2: print_usage() sys.exit() # Init logging to console logging.init(3) try: config = get_conf(CFG_PATH) if sys.argv[1].lower() == 'start': msg_stdout('Running on Python %s' % sys.version.replace('\n', '')) aliases = get_aliases(config['get']['aliases_file']) check_aliases(config['get']['base_dir'], aliases) if not aliases: msg_stdout('File aliases absent', 1) else: msg_stdout('%d file aliases loaded' % len(aliases)) server = AsyncHTTPServer(config, SFSHTTPHandler)