diff --git a/plinth/settings.py b/plinth/settings.py index 1ee546f73..effb75744 100644 --- a/plinth/settings.py +++ b/plinth/settings.py @@ -86,6 +86,7 @@ INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.messages', + 'django.contrib.sessions', 'stronghold', 'plinth', ] diff --git a/plinth/web_framework.py b/plinth/web_framework.py index 2477185b0..80eb5ec26 100644 --- a/plinth/web_framework.py +++ b/plinth/web_framework.py @@ -15,7 +15,7 @@ import django.core.wsgi from django.conf import global_settings from django.contrib.messages import constants as message_constants -from . import cfg, log, module_loader, settings +from . import cfg, glib, log, module_loader, settings logger = logging.getLogger(__name__) @@ -59,6 +59,9 @@ def init(): interactive=False, verbosity=verbosity) os.chmod(cfg.store_file, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) + # Cleanup expired sessions every day + glib.schedule(24 * 3600, _cleanup_expired_sessions, in_thread=True) + def _get_secret_key(): """Retrieve or create a new Django secret key.""" @@ -105,6 +108,12 @@ def get_languages(): ]) +def _cleanup_expired_sessions(data): + """Cleanup expired Django sessions.""" + verbosity = 1 if cfg.develop else 0 + django.core.management.call_command('clearsessions', verbosity=verbosity) + + def get_wsgi_application(): """Return Django wsgi application.""" return django.core.wsgi.get_wsgi_application()