mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-04-02 00:07:16 +01:00
Check running container env before using Unix socket
Split use_unix_socket into two properties to handle the Supervisor upgrade transition where Core is still running with a container started by the old Supervisor (without SUPERVISOR_CORE_API_SOCKET): - supports_unix_socket: version check only, used when creating the Core container to decide whether to set the env var - use_unix_socket: version check + running container env check, used for communication decisions This ensures TCP fallback during the upgrade transition while still hard-failing if the socket is missing after Supervisor configured Core to use it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -184,7 +184,7 @@ class DockerHomeAssistant(DockerInterface):
|
||||
}
|
||||
if restore_job_id:
|
||||
environment[ENV_RESTORE_JOB_ID] = restore_job_id
|
||||
if self.sys_homeassistant.api.use_unix_socket:
|
||||
if self.sys_homeassistant.api.supports_unix_socket:
|
||||
environment[ENV_CORE_API_SOCKET] = "/run/supervisor/core.sock"
|
||||
if self.sys_homeassistant.duplicate_log_file:
|
||||
environment[ENV_DUPLICATE_LOG_FILE] = "1"
|
||||
|
||||
@@ -15,6 +15,7 @@ from multidict import MultiMapping
|
||||
|
||||
from ..const import SOCKET_CORE
|
||||
from ..coresys import CoreSys, CoreSysAttributes
|
||||
from ..docker.const import ENV_CORE_API_SOCKET
|
||||
from ..exceptions import HomeAssistantAPIError, HomeAssistantAuthError
|
||||
from ..utils import version_is_new_enough
|
||||
from .const import LANDINGPAGE
|
||||
@@ -51,8 +52,11 @@ class HomeAssistantAPI(CoreSysAttributes):
|
||||
self._logged_transport: bool = False
|
||||
|
||||
@property
|
||||
def use_unix_socket(self) -> bool:
|
||||
"""Return True if Core supports Unix socket communication."""
|
||||
def supports_unix_socket(self) -> bool:
|
||||
"""Return True if the installed Core version supports Unix socket communication.
|
||||
|
||||
Used to decide whether to configure the env var when starting Core.
|
||||
"""
|
||||
return (
|
||||
self.sys_homeassistant.version is not None
|
||||
and self.sys_homeassistant.version != LANDINGPAGE
|
||||
@@ -61,6 +65,24 @@ class HomeAssistantAPI(CoreSysAttributes):
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def use_unix_socket(self) -> bool:
|
||||
"""Return True if the running Core container is configured for Unix socket.
|
||||
|
||||
Checks both version support and that the container was actually started
|
||||
with the SUPERVISOR_CORE_API_SOCKET env var. This prevents failures
|
||||
during Supervisor upgrades where Core is still running with a container
|
||||
started by the old Supervisor.
|
||||
"""
|
||||
if not self.supports_unix_socket:
|
||||
return False
|
||||
meta_config = self.sys_homeassistant.core.instance.meta_config
|
||||
if not meta_config or "Env" not in meta_config:
|
||||
return False
|
||||
return any(
|
||||
env.startswith(f"{ENV_CORE_API_SOCKET}=") for env in meta_config["Env"]
|
||||
)
|
||||
|
||||
@property
|
||||
def session(self) -> aiohttp.ClientSession:
|
||||
"""Return session for Core communication.
|
||||
|
||||
Reference in New Issue
Block a user