Skip to content

Commit ce8ef23

Browse files
committed
Merge pull request #393 from marksteve/restart
Implement restart command (Closes #98)
2 parents ee6bb9a + e224c4c commit ce8ef23

5 files changed

Lines changed: 37 additions & 0 deletions

File tree

fig/cli/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class TopLevelCommand(Command):
9191
scale Set number of containers for a service
9292
start Start services
9393
stop Stop services
94+
restart Restart services
9495
up Create and start containers
9596
9697
"""
@@ -336,6 +337,14 @@ def stop(self, project, options):
336337
"""
337338
project.stop(service_names=options['SERVICE'])
338339

340+
def restart(self, project, options):
341+
"""
342+
Restart running containers.
343+
344+
Usage: restart [SERVICE...]
345+
"""
346+
project.restart(service_names=options['SERVICE'])
347+
339348
def up(self, project, options):
340349
"""
341350
Build, (re)create, start and attach to containers for a service.

fig/container.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ def stop(self, **options):
123123
def kill(self):
124124
return self.client.kill(self.id)
125125

126+
def restart(self):
127+
return self.client.restart(self.id)
128+
126129
def remove(self, **options):
127130
return self.client.remove_container(self.id, **options)
128131

fig/project.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ def kill(self, service_names=None, **options):
156156
for service in reversed(self.get_services(service_names)):
157157
service.kill(**options)
158158

159+
def restart(self, service_names=None, **options):
160+
for service in self.get_services(service_names):
161+
service.restart(**options)
162+
159163
def build(self, service_names=None, no_cache=False):
160164
for service in self.get_services(service_names):
161165
if service.can_be_built():

fig/service.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ def kill(self, **options):
108108
log.info("Killing %s..." % c.name)
109109
c.kill(**options)
110110

111+
def restart(self, **options):
112+
for c in self.containers():
113+
log.info("Restarting %s..." % c.name)
114+
c.restart(**options)
115+
111116
def scale(self, desired_num):
112117
"""
113118
Adjusts the number of containers to the specified number and ensures they are running.

tests/integration/cli_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,22 @@ def test_rm(self):
194194
self.command.dispatch(['rm', '--force'], None)
195195
self.assertEqual(len(service.containers(stopped=True)), 0)
196196

197+
def test_restart(self):
198+
service = self.project.get_service('simple')
199+
container = service.create_container()
200+
service.start_container(container)
201+
started_at = container.dictionary['State']['StartedAt']
202+
self.command.dispatch(['restart'], None)
203+
container.inspect()
204+
self.assertNotEqual(
205+
container.dictionary['State']['FinishedAt'],
206+
'0001-01-01T00:00:00Z',
207+
)
208+
self.assertNotEqual(
209+
container.dictionary['State']['StartedAt'],
210+
started_at,
211+
)
212+
197213
def test_scale(self):
198214
project = self.project
199215

0 commit comments

Comments
 (0)