Prevent boot loop (#1711)

* Prevent boot loop

* sort
This commit is contained in:
Pascal Vizeli 2020-05-08 16:13:36 +02:00 committed by GitHub
parent 2bc2a476d9
commit 81413d08ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 5 deletions

View File

@ -3,6 +3,7 @@ from datetime import datetime
import logging
import os
from pathlib import Path, PurePath
from typing import Optional
from .const import (
ATTR_ADDONS_CUSTOM_LIST,
@ -11,6 +12,7 @@ from .const import (
ATTR_LAST_BOOT,
ATTR_LOGGING,
ATTR_TIMEZONE,
ATTR_VERSION,
ATTR_WAIT_BOOT,
ENV_SUPERVISOR_SHARE,
FILE_HASSIO_CONFIG,
@ -59,6 +61,16 @@ class CoreConfig(JsonConfig):
"""Set system timezone."""
self._data[ATTR_TIMEZONE] = value
@property
def version(self) -> Optional[str]:
"""Return config version."""
return self._data.get(ATTR_VERSION)
@version.setter
def version(self, value: str):
"""Set config version."""
self._data[ATTR_VERSION] = str
@property
def wait_boot(self) -> int:
"""Return wait time for auto boot stages."""

View File

@ -25,11 +25,22 @@ class Core(CoreSysAttributes):
"""Initialize Supervisor object."""
self.coresys: CoreSys = coresys
self.state: CoreStates = CoreStates.INITIALIZE
self.healthy: bool = True
async def connect(self):
"""Connect Supervisor container."""
await self.sys_supervisor.load()
# Check if system is healthy
if self.sys_dev:
self.sys_config.version = self.sys_supervisor.version
elif (
self.sys_config.version
and self.sys_config.version != self.sys_supervisor.version
):
self.healthy = False
_LOGGER.fatal("System running in a unhealthy state. Please update you OS!")
async def setup(self):
"""Setup supervisor orchestration."""
self.state = CoreStates.STARTUP
@ -90,8 +101,8 @@ class Core(CoreSysAttributes):
# On release channel, try update itself
if self.sys_supervisor.need_update:
try:
if self.sys_dev:
_LOGGER.warning("Ignore Supervisor updates on dev!")
if self.sys_dev or not self.healthy:
_LOGGER.warning("Ignore Supervisor updates!")
else:
await self.sys_supervisor.update()
except SupervisorUpdateError:

View File

@ -101,7 +101,7 @@ class HassOS(CoreSysAttributes):
if cpe.get_product()[0] != "hassos":
raise NotImplementedError()
except NotImplementedError:
_LOGGER.debug("Found no HassOS")
_LOGGER.warning("No Home Assistant Operating-System found!")
return
else:
self._available = True

View File

@ -3,8 +3,8 @@ import asyncio
import logging
from typing import Dict, List
from ..coresys import CoreSys, CoreSysAttributes
from ..const import REPOSITORY_CORE, REPOSITORY_LOCAL
from ..coresys import CoreSys, CoreSysAttributes
from .addon import AddonStore
from .data import StoreData
from .repository import Repository

View File

@ -124,6 +124,9 @@ class Supervisor(CoreSysAttributes):
except DockerAPIError:
_LOGGER.error("Update of Supervisor fails!")
raise SupervisorUpdateError() from None
else:
self.sys_config.version = version
self.sys_config.save_data()
with suppress(SupervisorError):
await self.update_apparmor()

View File

@ -100,7 +100,7 @@ DOCKER_PORTS_DESCRIPTION = vol.Schema(
SCHEMA_HASS_CONFIG = vol.Schema(
{
vol.Optional(ATTR_UUID, default=lambda: uuid.uuid4().hex): uuid_match,
vol.Optional(ATTR_VERSION): vol.Maybe(vol.Coerce(str)),
vol.Optional(ATTR_VERSION): vol.Coerce(str),
vol.Optional(ATTR_IMAGE): docker_image,
vol.Optional(ATTR_ACCESS_TOKEN): token,
vol.Optional(ATTR_BOOT, default=True): vol.Boolean(),
@ -151,6 +151,7 @@ SCHEMA_SUPERVISOR_CONFIG = vol.Schema(
{
vol.Optional(ATTR_TIMEZONE, default="UTC"): validate_timezone,
vol.Optional(ATTR_LAST_BOOT): vol.Coerce(str),
vol.Optional(ATTR_VERSION): vol.Coerce(str),
vol.Optional(
ATTR_ADDONS_CUSTOM_LIST,
default=["https://github.com/hassio-addons/repository"],