def start(): CONF(project='storyboard') api_root = setup_app() # Create the WSGI server and start it host = cfg.CONF.bind_host port = cfg.CONF.bind_port srv = simple_server.make_server(host, port, api_root) LOG.info(_LI('Starting server in PID %s') % os.getpid()) LOG.info(_LI("Configuration:")) if host == '0.0.0.0': LOG.info( _LI('serving on 0.0.0.0:%(port)s, view at http://127.0.0.1:%(port)s' ) % ({ 'port': port })) else: LOG.info( _LI("serving on http://%(host)s:%(port)s") % ({ 'host': host, 'port': port })) srv.serve_forever()
def acquire(self): basedir = os.path.dirname(self.fname) if not os.path.exists(basedir): fileutils.ensure_tree(basedir) LOG.info(_LI('Created lock path: %s'), basedir) self.lockfile = open(self.fname, 'w') while True: try: # Using non-blocking locks since green threads are not # patched to deal with blocking locking calls. # Also upon reading the MSDN docs for locking(), it seems # to have a laughable 10 attempts "blocking" mechanism. self.trylock() LOG.debug('Got file lock "%s"', self.fname) return True except IOError as e: if e.errno in (errno.EACCES, errno.EAGAIN): # external locks synchronise things like iptables # updates - give it some time to prevent busy spinning time.sleep(0.01) else: raise threading.ThreadError(_("Unable to acquire lock on" " `%(filename)s` due to" " %(exception)s") % { 'filename': self.fname, 'exception': e, })
def _connect(self): """This method connects to RabbitMQ, establishes a channel, declares the storyboard exchange if it doesn't yet exist, and executes any post-connection hooks that an extending class may have registered. """ # If the closing flag is set, just exit. if self._closing: return # If a timer is set, kill it. if self._timer: LOG.debug(_('Clearing timer...')) self._timer.cancel() self._timer = None # Create the connection LOG.info(_LI('Connecting to %s'), self._connection_parameters.host) self._connection = pika.BlockingConnection(self._connection_parameters) # Create a channel LOG.debug(_('Creating a new channel')) self._channel = self._connection.channel() self._channel.confirm_delivery() # Declare the exchange LOG.debug(_('Declaring exchange %s'), self._exchange_name) self._channel.exchange_declare(exchange=self._exchange_name, exchange_type='topic', durable=True, auto_delete=False) # Set the open flag and execute any connection hooks. self._open = True self._execute_open_hooks()
def acquire(self): basedir = os.path.dirname(self.fname) if not os.path.exists(basedir): fileutils.ensure_tree(basedir) LOG.info(_LI('Created lock path: %s'), basedir) self.lockfile = open(self.fname, 'w') while True: try: # Using non-blocking locks since green threads are not # patched to deal with blocking locking calls. # Also upon reading the MSDN docs for locking(), it seems # to have a laughable 10 attempts "blocking" mechanism. self.trylock() LOG.debug('Got file lock "%s"', self.fname) return True except IOError as e: if e.errno in (errno.EACCES, errno.EAGAIN): # external locks synchronise things like iptables # updates - give it some time to prevent busy spinning time.sleep(0.01) else: raise threading.ThreadError( _("Unable to acquire lock on" " `%(filename)s` due to" " %(exception)s") % { 'filename': self.fname, 'exception': e, })
def start(self): """Start the daemon manager and spawn child processes. """ LOG.info( _LI("Spawning %s child processes") % (self._child_process_count, )) self._timer.start() for i in range(self._child_process_count): self._add_process()
def start(self): """Start the daemon manager and spawn child processes. """ LOG.info(_LI("Spawning %s child processes") % (self._child_process_count,)) self._timer.start() for i in range(self._child_process_count): self._add_process()
def remove_external_lock_file(name, lock_file_prefix=None): """Remove a external lock file when it's not used anymore This will be helpful when we have a lot of lock files """ with internal_lock(name): lock_file_path = _get_lock_path(name, lock_file_prefix) try: os.remove(lock_file_path) except OSError: LOG.info(_LI('Failed to remove file %(file)s'), {'file': lock_file_path})
def _close(self): """This method closes the connection to RabbitMQ.""" LOG.info(_LI('Closing connection')) self._open = False if self._channel: self._channel.close() self._channel = None if self._connection: self._connection.close() self._connection = None self._closing = False LOG.debug(_('Connection Closed'))
def start(): CONF(project='storyboard') api_root = setup_app() # Create the WSGI server and start it host = cfg.CONF.bind_host port = cfg.CONF.bind_port srv = simple_server.make_server(host, port, api_root) LOG.info(_LI('Starting server in PID %s') % os.getpid()) LOG.info(_LI("Configuration:")) if host == '0.0.0.0': LOG.info(_LI( 'serving on 0.0.0.0:%(port)s, view at http://127.0.0.1:%(port)s') % ({'port': port})) else: LOG.info(_LI("serving on http://%(host)s:%(port)s") % ( {'host': host, 'port': port})) srv.serve_forever()