Пример #1
0
    def __restart(self, state, containers=[], time=docker.DOCKER_STOP_TIME):
        ops = []
        for container in containers:
            if container not in state:
                logger.error("'%s' does not exist." % container)
            else:
                if state[container].running:
                    op = docker.stop(container, time=time) \
                        .then(defer(docker.start, container=container)) \
                        .then(dinfo("'%s' has been restarted." % container)) \
                        .then(defer(self.writePid, container=container))
                    ops.append(op)
                else:
                    ops.append(docker.start(container)
                        .then(dinfo("'%s' has been started." % container))) \
                        .then(defer(self.writePid, container=container))

        return Try.sequence(ops)
Пример #2
0
 def __start(self, state, containers=[]):
     ops = []
     for container in containers:
         if container not in state:
             op = docker.create(container, self.getContainerConfig(container), basePath=self.getBasePath(),  networks=self.getNetworks()) \
                 .then(defer(docker.start, container=container)) \
                 .then(dinfo("'%s' has been created and started." % container))  \
                 .then(defer(self.writePid, container=container))
             ops.append(op)
         else:
             if not state[container].running:
                 op = docker.start(container) \
                     .then(dinfo("'%s' has been started." % container)) \
                     .then(defer(self.writePid, container=container))
                 ops.append(op)
             else:
                 logger.warn("'%s' is already running." % container)
     return Try.sequence(ops)