Skip to content

Commit

Permalink
In kolibri-daemon, automatically provision Kolibri
Browse files Browse the repository at this point in the history
With this change, kolibri-daemon generates an automatic_provision.json
file before starting Kolibri. Because Kolibri must be initialized early
in the application's lifecycle, it would be a nontrivial effort to make
this happen conditionally. For simplicity, kolibri-daemon will always
generate this file, even when Kolibri is running as a session service.
This is a change from the previous release, where automatic provisioning
only applied for Kolibri as a system service.

It is possible to go back to the old behaviour by running kolibri-daemon
with the environment variable `DAEMON_DISABLE_AUTOMATIC_PROVISION=yes`.

learningequality/kolibri-installer-gnome#87
#7
  • Loading branch information
dylanmccall committed Sep 1, 2023
1 parent 5774fd5 commit 8174258
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 57 deletions.

This file was deleted.

4 changes: 4 additions & 0 deletions src/kolibri_app/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
config.PROFILE_ENV_PREFIX + "APP_FORCE_AUTOMATIC_LOGIN"
)

DAEMON_DISABLE_AUTOMATIC_PROVISION = os.environ.get(
config.PROFILE_ENV_PREFIX + "DAEMON_DISABLE_AUTOMATIC_PROVISION"
)

XDG_CURRENT_DESKTOP = os.environ.get("XDG_CURRENT_DESKTOP")

# Logic for KOLIBRI_HOME is from kolibri.utils.conf. We avoid importing it from
Expand Down
44 changes: 36 additions & 8 deletions src/kolibri_daemon/kolibri_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import json
import logging
import os
import platform
import shutil
import typing
from gettext import gettext as _
from pathlib import Path

from kolibri_app.config import KOLIBRI_HOME_TEMPLATE_DIR
from kolibri_app.globals import DAEMON_DISABLE_AUTOMATIC_PROVISION
from kolibri_app.globals import KOLIBRI_HOME_PATH

from .content_extensions_manager import ContentExtensionsManager
Expand Down Expand Up @@ -40,14 +43,14 @@ def init_kolibri(**kwargs):

from kolibri.utils.main import initialize

initialize(**kwargs)

for plugin_name in REQUIRED_PLUGINS:
_enable_kolibri_plugin(plugin_name)

for plugin_name in OPTIONAL_PLUGINS:
_enable_kolibri_plugin(plugin_name, optional=True)

initialize(**kwargs)


def _init_kolibri_env():
os.environ["DJANGO_SETTINGS_MODULE"] = "kolibri_app.kolibri_settings"
Expand All @@ -57,10 +60,8 @@ def _init_kolibri_env():
# workload, we can use a smaller number of threads.
os.environ.setdefault("KOLIBRI_CHERRYPY_THREAD_POOL", "10")

# Automatically provision with $KOLIBRI_HOME/automatic_provision.json if it
# exists.
# TODO: Once kolibri-gnome supports automatic login for all cases, use an
# included automatic provision file by default.
# Automatically provision with $KOLIBRI_HOME/automatic_provision.json or a
# generated automatic_provision.json if applicable.
automatic_provision_path = _get_automatic_provision_path()
if automatic_provision_path:
os.environ.setdefault(
Expand Down Expand Up @@ -90,10 +91,37 @@ def _enable_kolibri_plugin(plugin_name: str, optional=False) -> bool:
def _get_automatic_provision_path() -> typing.Optional[Path]:
path = KOLIBRI_HOME_PATH.joinpath("automatic_provision.json")

if not path.is_file():
if path.is_file():
return path
elif not DAEMON_DISABLE_AUTOMATIC_PROVISION:
# TODO: Only do this if Kolibri does not have a facility configured.
with path.open("w") as file:
json.dump(_get_automatic_provision_data(), file)
return path
else:
return None

return path

def _get_automatic_provision_data():
facility_name = _("Kolibri on {host}").format(host=platform.node() or "localhost")
return {
"facility": {
"name": facility_name,
"learner_can_login_with_no_password": False,
},
"preset": "formal",
"superuser": {
"username": None,
"password": None,
},
"language_id": None,
"device_name": None,
"settings": {
"landing_page": "learn",
"allow_other_browsers_to_connect": False,
},
"allow_guest_access": False,
}


def _kolibri_update_from_home_template():
Expand Down

0 comments on commit 8174258

Please sign in to comment.