lifecycle: run bootstrap tasks inline when using automated install

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-06-09 20:09:51 +02:00
parent 66f4a31b4c
commit 7beebe030d
3 changed files with 27 additions and 5 deletions

View File

@ -0,0 +1,13 @@
"""Run bootstrap tasks"""
from django.core.management.base import BaseCommand
from authentik.root.celery import _get_startup_tasks
class Command(BaseCommand): # pragma: no cover
"""Run bootstrap tasks to ensure certain objects are created"""
def handle(self, **options):
tasks = _get_startup_tasks()
for task in tasks:
task()

View File

@ -1,6 +1,7 @@
"""authentik core celery"""
import os
from logging.config import dictConfig
from typing import Callable
from celery import Celery
from celery.signals import (
@ -76,23 +77,28 @@ def task_error_hook(task_id, exception: Exception, traceback, *args, **kwargs):
Event.new(EventAction.SYSTEM_EXCEPTION, message=exception_to_string(exception)).save()
@worker_ready.connect
def worker_ready_hook(*args, **kwargs):
"""Run certain tasks on worker start"""
def _get_startup_tasks() -> list[Callable]:
"""Get all tasks to be run on startup"""
from authentik.admin.tasks import clear_update_notifications
from authentik.managed.tasks import managed_reconcile
from authentik.outposts.tasks import outpost_controller_all, outpost_local_connection
from authentik.providers.proxy.tasks import proxy_set_defaults
tasks = [
return [
clear_update_notifications,
outpost_local_connection,
outpost_controller_all,
proxy_set_defaults,
managed_reconcile,
]
@worker_ready.connect
def worker_ready_hook(*args, **kwargs):
"""Run certain tasks on worker start"""
LOGGER.info("Dispatching startup tasks...")
for task in tasks:
for task in _get_startup_tasks():
try:
task.delay()
except ProgrammingError as exc:

View File

@ -38,6 +38,9 @@ if [[ "$1" == "server" ]]; then
wait_for_db
echo "server" > $MODE_FILE
python -m lifecycle.migrate
if [[ ! -z "${AUTHENTIK_BOOTSTRAP_PASSWORD}" || ! -z "${AUTHENTIK_BOOTSTRAP_TOKEN}" ]]; then
python -m manage bootstrap_tasks
fi
/authentik-proxy
elif [[ "$1" == "worker" ]]; then
wait_for_db