mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-15 05:06:30 +00:00
Use own coredns for supervisor
This commit is contained in:
parent
2480c83169
commit
b6c81d779a
@ -19,6 +19,7 @@ from .validate import SCHEMA_DNS_CONFIG
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
COREDNS_TMPL: Path = Path(__file__).parents[0].joinpath("data/coredns.tmpl")
|
||||
RESOLV_CONF: Path = Path("/etc/resolv.conf")
|
||||
|
||||
|
||||
class CoreDNS(JsonConfig, CoreSysAttributes):
|
||||
@ -100,6 +101,9 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
|
||||
# Start DNS forwarder
|
||||
self.sys_create_task(self.forwarder.start(self.sys_docker.network.dns))
|
||||
|
||||
with suppress(CoreDNSError):
|
||||
self._update_local_resolv()
|
||||
|
||||
# Start is not Running
|
||||
if await self.instance.is_running():
|
||||
return
|
||||
@ -293,7 +297,7 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
|
||||
"""
|
||||
return self.instance.is_fails()
|
||||
|
||||
async def repair(self):
|
||||
async def repair(self) -> None:
|
||||
"""Repair CoreDNS plugin."""
|
||||
if await self.instance.exists():
|
||||
return
|
||||
@ -303,3 +307,31 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
|
||||
await self.instance.install(self.version)
|
||||
except DockerAPIError:
|
||||
_LOGGER.error("Repairing of CoreDNS fails")
|
||||
|
||||
def _update_local_resolv(self) -> None:
|
||||
"""Update local resolv file."""
|
||||
resolv_lines: List[str] = []
|
||||
nameserver = f"nameserver {self.sys_docker.network.dns!s}"
|
||||
|
||||
# Read resolv config
|
||||
try:
|
||||
with RESOLV_CONF.open("r") as resolv:
|
||||
for line in resolv.readlines():
|
||||
resolv_lines.append(line)
|
||||
except OSError as err:
|
||||
_LOGGER.error("Can't read local resolve: %s", err)
|
||||
raise CoreDNSError() from None
|
||||
|
||||
if nameserver in resolv_lines:
|
||||
return
|
||||
_LOGGER.info("Update resolv from Supervisor")
|
||||
|
||||
# Write config back to resolv
|
||||
resolv_lines.append(nameserver)
|
||||
try:
|
||||
with RESOLV_CONF.open("w") as resolv:
|
||||
for line in resolv_lines:
|
||||
resolv.write(line)
|
||||
except OSError as err:
|
||||
_LOGGER.error("Can't write local resolve: %s", err)
|
||||
raise CoreDNSError() from None
|
||||
|
Loading…
x
Reference in New Issue
Block a user