mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-27 19:16:29 +00:00
Detect running record migration (#659)
* Detect running record migration * Fix order * Change order second one
This commit is contained in:
parent
d81bc7de46
commit
0b85209eae
@ -4,6 +4,7 @@ from contextlib import asynccontextmanager, suppress
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from pathlib import Path
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -437,6 +438,9 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
|
|||||||
async def _block_till_run(self):
|
async def _block_till_run(self):
|
||||||
"""Block until Home-Assistant is booting up or startup timeout."""
|
"""Block until Home-Assistant is booting up or startup timeout."""
|
||||||
start_time = time.monotonic()
|
start_time = time.monotonic()
|
||||||
|
migration_progress = False
|
||||||
|
migration_file = Path(
|
||||||
|
self.sys_config.path_homeassistant, '.migration_progress')
|
||||||
|
|
||||||
def check_port():
|
def check_port():
|
||||||
"""Check if port is mapped."""
|
"""Check if port is mapped."""
|
||||||
@ -452,21 +456,39 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
|
|||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
while time.monotonic() - start_time < self.wait_boot:
|
while True:
|
||||||
|
await asyncio.sleep(10)
|
||||||
|
|
||||||
|
# 1
|
||||||
|
# Check if Container is is_running
|
||||||
|
if not await self.instance.is_running():
|
||||||
|
_LOGGER.error("HomeAssistant is crashed!")
|
||||||
|
break
|
||||||
|
|
||||||
|
# 2
|
||||||
# Check if API response
|
# Check if API response
|
||||||
if await self.sys_run_in_executor(check_port):
|
if await self.sys_run_in_executor(check_port):
|
||||||
_LOGGER.info("Detect a running HomeAssistant instance")
|
_LOGGER.info("Detect a running HomeAssistant instance")
|
||||||
self._error_state = False
|
self._error_state = False
|
||||||
return
|
return
|
||||||
|
|
||||||
# wait and don't hit the system
|
# 3
|
||||||
await asyncio.sleep(10)
|
# Running DB Migration
|
||||||
|
if migration_file.exists():
|
||||||
|
if not migration_progress:
|
||||||
|
migration_progress = True
|
||||||
|
_LOGGER.info("HomeAssistant record migration in progress")
|
||||||
|
continue
|
||||||
|
elif migration_progress:
|
||||||
|
migration_progress = False # Reset start time
|
||||||
|
start_time = time.monotonic()
|
||||||
|
_LOGGER.info("HomeAssistant record migration done")
|
||||||
|
|
||||||
# Check if Container is is_running
|
# 4
|
||||||
if not await self.instance.is_running():
|
# Timeout
|
||||||
_LOGGER.error("Home Assistant is crashed!")
|
if time.monotonic() - start_time > self.wait_boot:
|
||||||
|
_LOGGER.warning("Don't wait anymore of HomeAssistant startup!")
|
||||||
break
|
break
|
||||||
|
|
||||||
_LOGGER.warning("Don't wait anymore of HomeAssistant startup!")
|
|
||||||
self._error_state = True
|
self._error_state = True
|
||||||
raise HomeAssistantError()
|
raise HomeAssistantError()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user