Skip to content

Commit d0d2a08

Browse files
author
Matthew Fisher
committed
feat(controller): restart individual processes
1 parent 2e76cf1 commit d0d2a08

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

client/deis.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,12 +1747,14 @@ def ps_restart(self, args):
17471747
Arguments:
17481748
<type>
17491749
the process name as defined in your Procfile, such as 'web' or 'worker'.
1750+
To restart a particular process, use 'web.1'.
17501751
17511752
Options:
17521753
-a --app=<app>
17531754
the uniquely identifiable name for the application.
17541755
"""
17551756
app = args.get('--app')
1757+
procname = args.get('<type>')
17561758
if not app:
17571759
app = self._session.app
17581760
restarting_cmd = 'Restarting processes... but first, {}!\n'.format(
@@ -1764,9 +1766,15 @@ def ps_restart(self, args):
17641766
progress.start()
17651767
before = time.time()
17661768
url = '/v1/apps/{}/containers/restart'.format(app)
1767-
if args.get('<type>'):
1768-
url = '/v1/apps/{}/containers/{}/restart'.format(app,
1769-
args.get('<type>'))
1769+
if procname:
1770+
if '.' in procname:
1771+
# format is web.2
1772+
proctype, procnum = procname.split('.')
1773+
url = '/v1/apps/{}/containers/{}/{}/restart'.format(app,
1774+
proctype,
1775+
procnum)
1776+
else:
1777+
url = '/v1/apps/{}/containers/{}/restart'.format(app, procname)
17701778
response = self._dispatch('post', url)
17711779
finally:
17721780
progress.cancel()

controller/api/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ def delete(self, *args, **kwargs):
201201
def restart(self, **kwargs):
202202
to_restart = self.container_set.all()
203203
if kwargs.get('type'):
204-
to_restart = self.container_set.filter(type=kwargs.get('type'))
204+
to_restart = to_restart.filter(type=kwargs.get('type'))
205+
if kwargs.get('num'):
206+
to_restart = to_restart.filter(num=kwargs.get('num'))
205207
self._restart_containers(to_restart)
206208
return to_restart
207209

controller/api/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
views.ContainerViewSet.as_view({'post': 'restart'})),
3131
url(r'^apps/(?P<id>{})/containers/(?P<type>[-_\w.]+)/restart/?'.format(settings.APP_URL_REGEX),
3232
views.ContainerViewSet.as_view({'post': 'restart'})),
33+
url(r'^apps/(?P<id>{})/containers/(?P<type>[-_\w]+)/(?P<num>[-_\w]+)/restart/?'.format(
34+
settings.APP_URL_REGEX),
35+
views.ContainerViewSet.as_view({'post': 'restart'})),
3336
url(r'^apps/(?P<id>{})/containers/(?P<type>[-_\w]+)/(?P<num>[-_\w]+)/?'.format(
3437
settings.APP_URL_REGEX),
3538
views.ContainerViewSet.as_view({'get': 'retrieve'})),

0 commit comments

Comments
 (0)