Abstract restart logic

This commit is contained in:
Pascal Vizeli 2018-04-09 22:13:16 +02:00
parent 6a84829c16
commit 92d5b14cf5
2 changed files with 9 additions and 34 deletions

View File

@ -264,31 +264,6 @@ class DockerInterface(CoreSysAttributes):
except docker.errors.DockerException as err:
_LOGGER.warning("Can't grap logs from %s: %s", self.image, err)
@process_lock
def restart(self):
"""Restart docker container."""
return self._loop.run_in_executor(None, self._restart)
def _restart(self):
"""Restart docker container.
Need run inside executor.
"""
try:
container = self._docker.containers.get(self.name)
except docker.errors.DockerException:
return False
_LOGGER.info("Restart %s", self.image)
try:
container.restart(timeout=self.timeout)
except docker.errors.DockerException as err:
_LOGGER.warning("Can't restart %s: %s", self.image, err)
return False
return True
@process_lock
def cleanup(self):
"""Check if old version exists and cleanup."""

View File

@ -218,15 +218,17 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
"""Start HomeAssistant docker & wait."""
if await self.instance.run():
await self._block_till_run()
return False
@process_lock
async def start(self):
"""Run HomeAssistant docker."""
if not await self.instance.run():
return False
def start(self):
"""Run HomeAssistant docker.
return await self._block_till_run()
Return a coroutine.
"""
return self._start()
@process_lock
def stop(self):
"""Stop HomeAssistant docker.
@ -237,10 +239,8 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
@process_lock
async def restart(self):
"""Restart HomeAssistant docker."""
if not await self.instance.restart():
return False
return await self._block_till_run()
await self.instance.stop()
return await self._start()
def logs(self):
"""Get HomeAssistant docker logs.