diff --git a/fig/cli/main.py b/fig/cli/main.py index eb19d46d8..5443fa6b7 100644 --- a/fig/cli/main.py +++ b/fig/cli/main.py @@ -90,6 +90,7 @@ class TopLevelCommand(Command): scale Set number of containers for a service start Start services stop Stop services + restart Restart services up Create and start containers """ @@ -315,6 +316,14 @@ class TopLevelCommand(Command): """ project.stop(service_names=options['SERVICE']) + def restart(self, project, options): + """ + Restart running containers. + + Usage: restart [SERVICE...] + """ + project.restart(service_names=options['SERVICE']) + def up(self, project, options): """ Build, (re)create, start and attach to containers for a service. diff --git a/fig/container.py b/fig/container.py index e9bbd59d3..28cb06ffb 100644 --- a/fig/container.py +++ b/fig/container.py @@ -117,6 +117,9 @@ class Container(object): def kill(self): return self.client.kill(self.id) + def restart(self): + return self.client.restart(self.id) + def remove(self, **options): return self.client.remove_container(self.id, **options) diff --git a/fig/project.py b/fig/project.py index 614b04899..9397c1167 100644 --- a/fig/project.py +++ b/fig/project.py @@ -155,6 +155,10 @@ class Project(object): for service in reversed(self.get_services(service_names)): service.kill(**options) + def restart(self, service_names=None, **options): + for service in self.get_services(service_names): + service.restart(**options) + def build(self, service_names=None, no_cache=False): for service in self.get_services(service_names): if service.can_be_built(): diff --git a/fig/service.py b/fig/service.py index 65bcf5197..c792d297c 100644 --- a/fig/service.py +++ b/fig/service.py @@ -89,6 +89,11 @@ class Service(object): log.info("Killing %s..." % c.name) c.kill(**options) + def restart(self, **options): + for c in self.containers(): + log.info("Restarting %s..." % c.name) + c.restart(**options) + def scale(self, desired_num): """ Adjusts the number of containers to the specified number and ensures they are running.