Update setting on startup (#1244)

* Update setting on startup

* Fix

* fix exception

* Cleanup handling
This commit is contained in:
Pascal Vizeli 2019-08-18 17:11:42 +02:00 committed by GitHub
parent 77be830b72
commit de3382226e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -120,7 +120,8 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
# Start is not Running
if await self.instance.is_running():
return
await self.restart()
else:
await self.start()
async def unload(self) -> None:
@ -146,6 +147,8 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
self.version = self.instance.version
self.save_data()
# Init Hosts / Run server
self.write_hosts()
await self.start()
async def update(self, version: Optional[str] = None) -> None:
@ -174,14 +177,13 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
async def restart(self) -> None:
"""Restart CoreDNS plugin."""
self._write_corefile()
with suppress(DockerAPIError):
await self.instance.stop()
await self.start()
await self.instance.restart()
async def start(self) -> None:
"""Run CoreDNS."""
self._write_corefile()
self.write_hosts()
# Start Instance
_LOGGER.info("Start CoreDNS plugin")
@ -195,6 +197,7 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
"""Reset Config / Hosts."""
self.servers = DNS_SERVERS
# Resets hosts
with suppress(OSError):
self.hosts.unlink()
self._init_hosts()
@ -343,7 +346,7 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
continue
resolv_lines.append(line.strip())
except OSError as err:
_LOGGER.error("Can't read local resolv: %s", err)
_LOGGER.warning("Can't read local resolv: %s", err)
raise CoreDNSError() from None
if nameserver in resolv_lines:
@ -357,5 +360,5 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
for line in resolv_lines:
resolv.write(f"{line}\n")
except OSError as err:
_LOGGER.error("Can't write local resolv: %s", err)
_LOGGER.warning("Can't write local resolv: %s", err)
raise CoreDNSError() from None