def _create_local_socket(self, init=0): """Create local Unix-socket to listen commands instead of signals. If I{init} is set then close old socket""" if init and self.__local_sock: try: os.unlink(self.__local_sock.getsockname()) self.__local_sock.shutdown(socket.SHUT_RDWR) logging.info('old local socket closed') except Exception as e: logging.warn('old local socket is already closed') try: os.unlink(self._config['server']['sock']) except: pass try: self.__local_sock = \ socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) # Non-blocking mode self.__local_sock.settimeout(0.0) self.__local_sock.bind(self._config['server']['sock']) self.__local_sock.listen(1) # Max num of queued connections except Exception as e: logging.critical('cannot create local socket') logging.error(e) raise e logging.info('local socket created and binded on %s' % \ self.__local_sock.getsockname())
def _create_bind_activate(self, init=0): """Create socket, bind and activate server""" try: self._create_new_socket(init) except Exception as e: logging.critical('cannot create new socket') logging.error(e) raise e try: self.server_bind() self.server_activate() except Exception as e: logging.critical('cannot bind/activate server: %s' %e) raise e logging.info('server binded and activated on %s:%s' % \ self.socket.getsockname())