Fix corrupt container on startup (#2122)

This commit is contained in:
Pascal Vizeli 2020-10-13 11:02:54 +02:00 committed by GitHub
parent 3f6453aa89
commit 8da686fc34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View File

@ -18,6 +18,7 @@ from .coresys import CoreSys, CoreSysAttributes
from .exceptions import ( from .exceptions import (
DockerError, DockerError,
HassioError, HassioError,
HomeAssistantCrashError,
HomeAssistantError, HomeAssistantError,
SupervisorUpdateError, SupervisorUpdateError,
) )
@ -241,8 +242,16 @@ class Core(CoreSysAttributes):
self.sys_homeassistant.boot self.sys_homeassistant.boot
and not await self.sys_homeassistant.core.is_running() and not await self.sys_homeassistant.core.is_running()
): ):
with suppress(HomeAssistantError): try:
await self.sys_homeassistant.core.start() await self.sys_homeassistant.core.start()
except HomeAssistantCrashError as err:
_LOGGER.warning("Can't start Home Assistant Core - rebuild")
self.sys_capture_exception(err)
with suppress(HomeAssistantError):
await self.sys_homeassistant.core.rebuild()
except HomeAssistantError as err:
self.sys_capture_exception(err)
else: else:
_LOGGER.info("Skip start of Home Assistant") _LOGGER.info("Skip start of Home Assistant")

View File

@ -20,6 +20,10 @@ class HomeAssistantUpdateError(HomeAssistantError):
"""Error on update of a Home Assistant.""" """Error on update of a Home Assistant."""
class HomeAssistantCrashError(HomeAssistantError):
"""Error on crash of a Home Assistant startup."""
class HomeAssistantAPIError(HomeAssistantError): class HomeAssistantAPIError(HomeAssistantError):
"""Home Assistant API exception.""" """Home Assistant API exception."""

View File

@ -15,7 +15,12 @@ from packaging import version as pkg_version
from ..coresys import CoreSys, CoreSysAttributes from ..coresys import CoreSys, CoreSysAttributes
from ..docker.homeassistant import DockerHomeAssistant from ..docker.homeassistant import DockerHomeAssistant
from ..docker.stats import DockerStats from ..docker.stats import DockerStats
from ..exceptions import DockerError, HomeAssistantError, HomeAssistantUpdateError from ..exceptions import (
DockerError,
HomeAssistantCrashError,
HomeAssistantError,
HomeAssistantUpdateError,
)
from ..utils import convert_to_ascii, process_lock from ..utils import convert_to_ascii, process_lock
_LOGGER: logging.Logger = logging.getLogger(__name__) _LOGGER: logging.Logger = logging.getLogger(__name__)
@ -392,7 +397,7 @@ class HomeAssistantCore(CoreSysAttributes):
break break
self._error_state = True self._error_state = True
raise HomeAssistantError() raise HomeAssistantCrashError()
async def repair(self): async def repair(self):
"""Repair local Home Assistant data.""" """Repair local Home Assistant data."""