Delaying reboot/shutdown with asyncio sleep to give API time to shut down.

This commit is contained in:
Roland 2023-08-18 11:55:14 -06:00
parent 5ffb8bee8d
commit 4cc00a9cb1
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
9 changed files with 71 additions and 49 deletions

View file

@ -25,7 +25,7 @@ from wrolpi.common import logger, get_config, wrol_mode_enabled, Base, get_media
from wrolpi.dates import now, strptime
from wrolpi.downloader import download_manager
from wrolpi.errors import WROLModeEnabled, APIError, HotspotError, InvalidDownload, \
HotspotPasswordTooShort, ShutdownFailed, RestartFailed
HotspotPasswordTooShort, NativeOnly
from wrolpi.events import get_events, Events
from wrolpi.files.lib import get_file_statistics, estimate_search
from wrolpi.vars import API_HOST, API_PORT, DOCKERIZED, API_DEBUG, API_ACCESS_LOG, API_WORKERS, API_AUTO_RELOAD, \
@ -504,16 +504,16 @@ async def post_search_estimate(_: Request, body: schema.SearchEstimateRequest):
@api_bp.post('/restart')
async def post_restart(_: Request):
if DOCKERIZED:
raise RestartFailed(f'Cannot restart when running in Docker')
raise NativeOnly(f'Cannot restart when running in Docker')
await admin.restart()
await admin.shutdown(reboot=True)
return response.empty(HTTPStatus.NO_CONTENT)
@api_bp.post('/shutdown')
async def post_shutdown(_: Request):
if DOCKERIZED:
raise ShutdownFailed(f'Cannot shutdown when running in Docker')
raise NativeOnly(f'Cannot shutdown when running in Docker')
await admin.shutdown()
return response.empty(HTTPStatus.NO_CONTENT)