Exemplo n.º 1
0
    def start(self):
        """ Starts a new instance of the component. Note that this does *not* update the proxy. """
        client = getDockerClient()
        self.logger.debug('Starting container for component %s',
                          self.getName())

        # Ensure that we have the image. If not, we try to download it.
        self.ensureImage(client)

        # Start the instance with the proper image ID.
        container = self.createContainer(client)
        report('Starting container ' + container['Id'][:12], component=self)

        if self.config.privileged:
            report('Container will be run in privileged mode', component=self)

        client.start(container,
                     binds=self.config.getBindings(container['Id']),
                     volumes_from=self.config.volumes_from,
                     privileged=self.config.privileged)

        # Health check until the instance is ready.
        report('Waiting for health checks...', component=self)

        # Start a health check thread to determine when the component is ready.
        timeout = self.config.getReadyCheckTimeout()
        readycheck_thread = Thread(target=self.readyCheck,
                                   args=[container, timeout])
        readycheck_thread.daemon = True
        readycheck_thread.start()

        # Wait for the health thread to finish.
        readycheck_thread.join(self.config.getReadyCheckTimeout())

        # If the thread is still alived, then our join timed out.
        if readycheck_thread.isAlive():
            report(
                'Timed out waiting for health checks. Stopping container...',
                component=self)
            client.stop(container)
            report('Container stopped', component=self)
            return None

        # Otherwise, the container is ready. Set it as starting.
        setContainerComponent(container, self.getName())
        setContainerStatus(container, 'starting')
        return container
Exemplo n.º 2
0
    def start(self):
        """ Starts a new instance of the component. Note that this does *not* update the proxy. """
        client = getDockerClient()
        self.logger.debug("Starting container for component %s", self.getName())

        # Ensure that we have the image. If not, we try to download it.
        self.ensureImage(client)

        # Start the instance with the proper image ID.
        container = self.createContainer(client)
        report("Starting container " + container["Id"][:12], component=self)

        if self.config.privileged:
            report("Container will be run in privileged mode", component=self)

        client.start(
            container,
            binds=self.config.getBindings(container["Id"]),
            volumes_from=self.config.volumes_from,
            privileged=self.config.privileged,
        )

        # Health check until the instance is ready.
        report("Waiting for health checks...", component=self)

        # Start a health check thread to determine when the component is ready.
        timeout = self.config.getReadyCheckTimeout()
        readycheck_thread = Thread(target=self.readyCheck, args=[container, timeout])
        readycheck_thread.daemon = True
        readycheck_thread.start()

        # Wait for the health thread to finish.
        readycheck_thread.join(self.config.getReadyCheckTimeout())

        # If the thread is still alived, then our join timed out.
        if readycheck_thread.isAlive():
            report("Timed out waiting for health checks. Stopping container...", component=self)
            client.stop(container)
            report("Container stopped", component=self)
            return None

        # Otherwise, the container is ready. Set it as starting.
        setContainerComponent(container, self.getName())
        setContainerStatus(container, "starting")
        return container
Exemplo n.º 3
0
 def start(self):
   """ Starts a new instance of the component. Note that this does *not* update the proxy. """
   client = getDockerClient()
   self.logger.debug('Starting container for component %s', self.getName())
   
   # Ensure that we have the image. If not, we try to download it.
   self.ensureImage(client)
   
   # Start the instance with the proper image ID.
   container = self.createContainer(client)
   report('Starting container ' + container['Id'], component = self)
   client.start(container)
   
   # Health check until the instance is ready.    
   report('Waiting for health checks...', component = self)
   
   # Start a health check thread to determine when the component is ready.
   timeout = self.config.getReadyCheckTimeout()
   readycheck_thread = Thread(target = self.readyCheck, args=[container, timeout])
   readycheck_thread.daemon = True
   readycheck_thread.start()
   
   # Wait for the health thread to finish.
   readycheck_thread.join(self.config.getReadyCheckTimeout())
   
   # If the thread is still alived, then our join timed out.
   if readycheck_thread.isAlive():
     report('Timed out waiting for health checks. Stopping container...', component = self)
     client.stop(container)
     report('Container stopped', component = self)
     return None
   
   # Otherwise, the container is ready. Set it as starting.
   setContainerComponent(container, self.getName()) 
   setContainerStatus(container, 'starting')
   return container