mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-13 20:26:29 +00:00
Timeout shutdown (#603)
* Don't wait too long for shutdown * Update log message * Fix timeout * Fast shudown
This commit is contained in:
parent
7f878bfac0
commit
9dea93142b
@ -235,13 +235,16 @@ class RestAPI(CoreSysAttributes):
|
|||||||
async def start(self):
|
async def start(self):
|
||||||
"""Run rest api webserver."""
|
"""Run rest api webserver."""
|
||||||
await self._runner.setup()
|
await self._runner.setup()
|
||||||
self._site = web.TCPSite(self._runner, "0.0.0.0", 80)
|
self._site = web.TCPSite(
|
||||||
|
self._runner, host="0.0.0.0", port=80, shutdown_timeout=5)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self._site.start()
|
await self._site.start()
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
_LOGGER.fatal(
|
_LOGGER.fatal(
|
||||||
"Failed to create HTTP server at 0.0.0.0:80 -> %s", err)
|
"Failed to create HTTP server at 0.0.0.0:80 -> %s", err)
|
||||||
|
else:
|
||||||
|
_LOGGER.info("Start API on %s", self.sys_docker.network.supervisor)
|
||||||
|
|
||||||
async def stop(self):
|
async def stop(self):
|
||||||
"""Stop rest api webserver."""
|
"""Stop rest api webserver."""
|
||||||
@ -251,3 +254,5 @@ class RestAPI(CoreSysAttributes):
|
|||||||
# Shutdown running API
|
# Shutdown running API
|
||||||
await self._site.stop()
|
await self._site.stop()
|
||||||
await self._runner.cleanup()
|
await self._runner.cleanup()
|
||||||
|
|
||||||
|
_LOGGER.info("Stop API on %s", self.sys_docker.network.supervisor)
|
||||||
|
@ -3,6 +3,8 @@ from contextlib import suppress
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import async_timeout
|
||||||
|
|
||||||
from .coresys import CoreSysAttributes
|
from .coresys import CoreSysAttributes
|
||||||
from .const import (
|
from .const import (
|
||||||
STARTUP_SYSTEM, STARTUP_SERVICES, STARTUP_APPLICATION, STARTUP_INITIALIZE)
|
STARTUP_SYSTEM, STARTUP_SERVICES, STARTUP_APPLICATION, STARTUP_INITIALIZE)
|
||||||
@ -65,7 +67,6 @@ class HassIO(CoreSysAttributes):
|
|||||||
|
|
||||||
# start api
|
# start api
|
||||||
await self.sys_api.start()
|
await self.sys_api.start()
|
||||||
_LOGGER.info("Start API on %s", self.sys_docker.network.supervisor)
|
|
||||||
|
|
||||||
# start addon mark as initialize
|
# start addon mark as initialize
|
||||||
await self.sys_addons.boot(STARTUP_INITIALIZE)
|
await self.sys_addons.boot(STARTUP_INITIALIZE)
|
||||||
@ -113,12 +114,18 @@ class HassIO(CoreSysAttributes):
|
|||||||
self.sys_scheduler.suspend = True
|
self.sys_scheduler.suspend = True
|
||||||
|
|
||||||
# process async stop tasks
|
# process async stop tasks
|
||||||
await asyncio.wait([
|
try:
|
||||||
self.sys_api.stop(),
|
with async_timeout.timeout(10):
|
||||||
self.sys_dns.stop(),
|
await asyncio.wait([
|
||||||
self.sys_websession.close(),
|
self.sys_api.stop(),
|
||||||
self.sys_websession_ssl.close()
|
self.sys_dns.stop(),
|
||||||
])
|
self.sys_websession.close(),
|
||||||
|
self.sys_websession_ssl.close()
|
||||||
|
])
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
_LOGGER.warning("Force Shutdown!")
|
||||||
|
|
||||||
|
_LOGGER.info("Hass.io is down")
|
||||||
|
|
||||||
async def shutdown(self):
|
async def shutdown(self):
|
||||||
"""Shutdown all running containers in correct order."""
|
"""Shutdown all running containers in correct order."""
|
||||||
|
@ -3,6 +3,8 @@ import asyncio
|
|||||||
import logging
|
import logging
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
|
import async_timeout
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
COMMAND = "socat UDP-RECVFROM:53,fork UDP-SENDTO:127.0.0.11:53"
|
COMMAND = "socat UDP-RECVFROM:53,fork UDP-SENDTO:127.0.0.11:53"
|
||||||
@ -38,5 +40,10 @@ class DNSForward:
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.proc.kill()
|
self.proc.kill()
|
||||||
await self.proc.wait()
|
try:
|
||||||
|
with async_timeout.timeout(5):
|
||||||
|
await self.proc.wait()
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
_LOGGER.warning("Stop waiting for DNS shutdown")
|
||||||
|
|
||||||
_LOGGER.info("Stop DNS forwarding")
|
_LOGGER.info("Stop DNS forwarding")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user