Skip to content
Snippets Groups Projects
Verified Commit 214f5bb4 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Use media storage for maintenance mode state file

Previously, we relied on either explicit configuration to place the
file in a writable location, or the webserver being able to write to
the source tree.

With a (probably even replicated) setup where nothing runs as root,
and al lstorages are thus read-only except for the media storage, we
need to put the maintenance file there.
parent 86a9b0e8
No related branches found
No related tags found
1 merge request!544Resolve "[Docker] Do not run as root"
......@@ -484,9 +484,10 @@ MAINTENANCE_MODE_IGNORE_IP_ADDRESSES = _settings.get(
)
MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS = "ipware.ip.get_ip"
MAINTENANCE_MODE_IGNORE_SUPERUSER = True
MAINTENANCE_MODE_STATE_FILE_PATH = _settings.get(
MAINTENANCE_MODE_STATE_FILE_NAME = _settings.get(
"maintenance.statefile", "maintenance_mode_state.txt"
)
MAINTENANCE_MODE_STATE_BACKEND = "aleksis.core.util.maintenance.DefaultStorageBackend"
DBBACKUP_STORAGE = _settings.get("backup.storage", "django.core.files.storage.FileSystemStorage")
DBBACKUP_STORAGE_OPTIONS = {"location": _settings.get("backup.location", "/var/backups/aleksis")}
......
from django.conf import settings
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from maintenance_mode.backends import AbstractStateBackend
class DefaultStorageBackend(AbstractStateBackend):
"""django-maintenance-mode backend using default cache."""
def get_value(self) -> bool:
filename = settings.MAINTENANCE_MODE_STATE_FILE_NAME
try:
with default_storage.open(filename) as statefile:
return bool(int(statefile.read()))
except IOError:
return False
def set_value(self, value: bool) -> None:
filename = settings.MAINTENANCE_MODE_STATE_FILE_NAME
if default_storage.exists(filename):
default_storage.delete(filename)
default_storage.save(filename, ContentFile(str(int(value))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment