'plum up' is now the special magic
'start' and 'stop' are now analogous to their Docker namesakes.
This commit is contained in:
parent
3bebd18de7
commit
a4710fa9e1
6 changed files with 119 additions and 69 deletions
|
|
@ -140,37 +140,43 @@ class TopLevelCommand(Command):
|
|||
service.start_container(container, ports=None)
|
||||
c.run()
|
||||
|
||||
def start(self, options):
|
||||
def up(self, options):
|
||||
"""
|
||||
Start all services
|
||||
Create and start containers
|
||||
|
||||
Usage: start [options]
|
||||
Usage: up [options]
|
||||
|
||||
Options:
|
||||
-d Detached mode: Run containers in the background, print new container names
|
||||
"""
|
||||
if options['-d']:
|
||||
self.project.start()
|
||||
return
|
||||
detached = options['-d']
|
||||
|
||||
running = []
|
||||
unstarted = []
|
||||
unstarted = self.project.create_containers()
|
||||
|
||||
for s in self.project.services:
|
||||
if len(s.containers()) == 0:
|
||||
unstarted.append((s, s.create_container()))
|
||||
else:
|
||||
running += s.containers(stopped=False)
|
||||
|
||||
log_printer = LogPrinter(running + [c for (s, c) in unstarted])
|
||||
if not detached:
|
||||
to_attach = self.project.containers() + [c for (s, c) in unstarted]
|
||||
print "Attaching to", list_containers(to_attach)
|
||||
log_printer = LogPrinter(to_attach, attach_params={'logs': True})
|
||||
|
||||
for (s, c) in unstarted:
|
||||
s.start_container(c)
|
||||
|
||||
try:
|
||||
log_printer.run()
|
||||
finally:
|
||||
self.project.stop()
|
||||
if detached:
|
||||
for (s, c) in unstarted:
|
||||
print c.name
|
||||
else:
|
||||
try:
|
||||
log_printer.run()
|
||||
finally:
|
||||
self.project.kill_and_remove(unstarted)
|
||||
|
||||
def start(self, options):
|
||||
"""
|
||||
Start all services
|
||||
|
||||
Usage: start
|
||||
"""
|
||||
self.project.start()
|
||||
|
||||
def stop(self, options):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -83,13 +83,18 @@ class Container(object):
|
|||
out[k] = v
|
||||
return out
|
||||
|
||||
@property
|
||||
def is_running(self):
|
||||
self.inspect_if_not_inspected()
|
||||
return self.dictionary['State']['Running']
|
||||
|
||||
def start(self, **options):
|
||||
log.info("Starting %s..." % self.name)
|
||||
return self.client.start(self.id, **options)
|
||||
|
||||
def stop(self):
|
||||
def stop(self, **options):
|
||||
log.info("Stopping %s..." % self.name)
|
||||
return self.client.stop(self.id)
|
||||
return self.client.stop(self.id, **options)
|
||||
|
||||
def kill(self):
|
||||
log.info("Killing %s..." % self.name)
|
||||
|
|
|
|||
|
|
@ -50,13 +50,29 @@ class Project(object):
|
|||
if service.name == name:
|
||||
return service
|
||||
|
||||
def start(self):
|
||||
def create_containers(self):
|
||||
"""
|
||||
Returns a list of (service, container) tuples,
|
||||
one for each service with no running containers.
|
||||
"""
|
||||
containers = []
|
||||
for service in self.services:
|
||||
service.start()
|
||||
if len(service.containers()) == 0:
|
||||
containers.append((service, service.create_container()))
|
||||
return containers
|
||||
|
||||
def stop(self):
|
||||
def kill_and_remove(self, tuples):
|
||||
for (service, container) in tuples:
|
||||
container.kill()
|
||||
container.remove()
|
||||
|
||||
def start(self, **options):
|
||||
for service in self.services:
|
||||
service.stop()
|
||||
service.start(**options)
|
||||
|
||||
def stop(self, **options):
|
||||
for service in self.services:
|
||||
service.stop(**options)
|
||||
|
||||
def containers(self, *args, **kwargs):
|
||||
l = []
|
||||
|
|
|
|||
|
|
@ -38,19 +38,14 @@ class Service(object):
|
|||
l.append(Container.from_ps(self.client, container))
|
||||
return l
|
||||
|
||||
def start(self):
|
||||
if len(self.containers()) == 0:
|
||||
return self.start_container()
|
||||
def start(self, **options):
|
||||
for c in self.containers(stopped=True):
|
||||
if not c.is_running:
|
||||
self.start_container(c, **options)
|
||||
|
||||
def stop(self):
|
||||
self.scale(0)
|
||||
|
||||
def scale(self, num):
|
||||
while len(self.containers()) < num:
|
||||
self.start_container()
|
||||
|
||||
while len(self.containers()) > num:
|
||||
self.stop_container()
|
||||
def stop(self, **options):
|
||||
for c in self.containers():
|
||||
c.stop(**options)
|
||||
|
||||
def create_container(self, one_off=False, **override_options):
|
||||
"""
|
||||
|
|
@ -99,11 +94,6 @@ class Service(object):
|
|||
)
|
||||
return container
|
||||
|
||||
def stop_container(self):
|
||||
container = self.containers()[-1]
|
||||
container.kill()
|
||||
container.remove()
|
||||
|
||||
def next_container_name(self, one_off=False):
|
||||
bits = [self.project, self.name]
|
||||
if one_off:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue