support systemd notify and watchdog
This commit is contained in:
@@ -10,6 +10,8 @@ import capport.utils.cli
|
||||
import capport.utils.ipneigh
|
||||
import trio
|
||||
|
||||
from capport.utils.sd_notify import open_sdnotify
|
||||
|
||||
from .app import app
|
||||
|
||||
|
||||
@@ -38,9 +40,19 @@ async def _run_hub(*, task_status=trio.TASK_STATUS_IGNORED) -> None:
|
||||
await app.shutdown()
|
||||
|
||||
|
||||
async def _setup(*, task_status=trio.TASK_STATUS_IGNORED):
|
||||
async with open_sdnotify() as sn:
|
||||
await sn.send('STATUS=Starting hub')
|
||||
async with trio.open_nursery() as nursery:
|
||||
await nursery.start(_run_hub)
|
||||
await sn.send('READY=1', 'STATUS=Ready for client requests')
|
||||
task_status.started()
|
||||
# continue running hub and systemd watchdog handler
|
||||
|
||||
|
||||
@app.before_serving
|
||||
async def init():
|
||||
app.debug = app.my_config.debug
|
||||
app.secret_key = app.my_config.cookie_secret
|
||||
capport.utils.cli.init_logger(app.my_config)
|
||||
await app.nursery.start(_run_hub)
|
||||
await app.nursery.start(_setup)
|
||||
|
Reference in New Issue
Block a user