]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: Run migration lock as the correct user (#9604)
authorTrenton H <797416+stumpylog@users.noreply.github.com>
Wed, 9 Apr 2025 21:15:38 +0000 (14:15 -0700)
committerGitHub <noreply@github.com>
Wed, 9 Apr 2025 21:15:38 +0000 (21:15 +0000)
docker/rootfs/etc/s6-overlay/s6-rc.d/init-migrations/migrate.sh [new file with mode: 0755]
docker/rootfs/etc/s6-overlay/s6-rc.d/init-migrations/run

diff --git a/docker/rootfs/etc/s6-overlay/s6-rc.d/init-migrations/migrate.sh b/docker/rootfs/etc/s6-overlay/s6-rc.d/init-migrations/migrate.sh
new file mode 100755 (executable)
index 0000000..93b45fd
--- /dev/null
@@ -0,0 +1,7 @@
+#!/command/with-contenv /usr/bin/bash
+# shellcheck shell=bash
+declare -r data_dir="${PAPERLESS_DATA_DIR:-/usr/src/paperless/data}"
+
+# shellcheck disable=SC2164
+cd "${PAPERLESS_SRC_DIR}"
+exec s6-setlock -n "${data_dir}/migration_lock" python3 manage.py migrate --skip-checks --no-input
index db0dc26d316dee44b50cc98209996c48e7e0f4c1..7777248863ba4785b5ca0b96fa78d727faffd809 100755 (executable)
@@ -1,20 +1,12 @@
 #!/command/with-contenv /usr/bin/bash
 # shellcheck shell=bash
 declare -r log_prefix="[init-migrations]"
-declare -r data_dir="${PAPERLESS_DATA_DIR:-/usr/src/paperless/data}"
 
-(
-       # flock is in place to prevent multiple containers from doing migrations
-       # simultaneously. This also ensures that the db is ready when the command
-       # of the current container starts.
-       flock 200
-       echo "${log_prefix} Apply database migrations..."
-       cd "${PAPERLESS_SRC_DIR}"
+echo "${log_prefix} Apply database migrations..."
 
-       if [[ -n "${USER_IS_NON_ROOT}" ]]; then
-               exec python3 manage.py migrate --skip-checks --no-input
-       else
-               exec s6-setuidgid paperless python3 manage.py migrate --skip-checks --no-input
-       fi
-
-) 200>"${data_dir}/migration_lock"
+# The whole migrate, with flock, needs to run as the right user
+if [[ -n "${USER_IS_NON_ROOT}" ]]; then
+       exec /etc/s6-overlay/s6-rc.d/init-migrations/migrate.sh
+else
+       exec s6-setuidgid paperless /etc/s6-overlay/s6-rc.d/init-migrations/migrate.sh
+fi