Skip to content

Commit

Permalink
use flock automatic lock for upgrade
Browse files Browse the repository at this point in the history
fix nextcloud#1756

fix nextcloud#1903

Signed-off-by: Adam Monsen <haircut@gmail.com>
  • Loading branch information
meonkeys committed Feb 8, 2023
1 parent f49b1ed commit e1cf8e6
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
rsync_options="-rlD"
fi

# Prevent multiple images syncing simultaneously:
# If another process is syncing the html folder, wait for
# it to be done, then escape initalization.
# You need to define the NEXTCLOUD_INIT_LOCK environment variable
lock=/var/www/html/nextcloud-init-sync.lock
# it to be done, then escape initalization
count=0
limit=10

if [ -f "$lock" ] && [ -n "${NEXTCLOUD_INIT_LOCK+x}" ]; then
until [ ! -f "$lock" ] || [ "$count" -gt "$limit" ]
(
if ! flock -n 9; then
until flock -n 9 || [ "$count" -gt "$limit" ]
do
count=$((count+1))
wait=$((count*10))
Expand All @@ -145,8 +145,6 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
fi
echo "The other process is done, assuming complete initialization"
else
# Prevent multiple images syncing simultaneously
touch $lock
rsync $rsync_options --delete --exclude-from=/upgrade.exclude /usr/src/nextcloud/ /var/www/html/

for dir in config data custom_apps themes; do
Expand Down Expand Up @@ -234,10 +232,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP

fi

# Initialization done, reset lock
rm $lock
echo "Initializing finished"
fi
) 9> /var/lock/nextcloud-init-sync.lock
fi

# Update htaccess after init if requested
Expand Down

0 comments on commit e1cf8e6

Please sign in to comment.