mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-10 03:01:29 -07:00
docker_container: use restart() API function instead of stop/start sequence (#55894)
* Improve container restart. * Adjust tests. * Add changelog. * Quote options. * Move tests for restart/recreate options to start/stop tests. * Fix changelog name.
This commit is contained in:
parent
93f0112953
commit
95d1564f70
4 changed files with 138 additions and 112 deletions
|
@ -2351,8 +2351,8 @@ class ContainerManager(DockerBaseClass):
|
|||
container = self.container_start(container.Id)
|
||||
elif state == 'started' and self.parameters.restart:
|
||||
self.diff_tracker.add('running', parameter=True, active=was_running)
|
||||
self.container_stop(container.Id)
|
||||
container = self.container_start(container.Id)
|
||||
self.diff_tracker.add('restarted', parameter=True, active=False)
|
||||
container = self.container_restart(container.Id)
|
||||
elif state == 'stopped' and container.running:
|
||||
self.diff_tracker.add('running', parameter=False, active=was_running)
|
||||
self.container_stop(container.Id)
|
||||
|
@ -2634,6 +2634,19 @@ class ContainerManager(DockerBaseClass):
|
|||
self.fail("Error killing container %s: %s" % (container_id, exc))
|
||||
return response
|
||||
|
||||
def container_restart(self, container_id):
|
||||
self.results['actions'].append(dict(restarted=container_id, timeout=self.parameters.stop_timeout))
|
||||
self.results['changed'] = True
|
||||
if not self.check_mode:
|
||||
try:
|
||||
if self.parameters.stop_timeout:
|
||||
response = self.client.restart(container_id, timeout=self.parameters.stop_timeout)
|
||||
else:
|
||||
response = self.client.restart(container_id)
|
||||
except Exception as exc:
|
||||
self.fail("Error restarting container %s: %s" % (container_id, str(exc)))
|
||||
return self._get_container(container_id)
|
||||
|
||||
def container_stop(self, container_id):
|
||||
if self.parameters.force_kill:
|
||||
self.container_kill(container_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue