From 63f1baad3e59b74c250b809d6c843db7aa016d9b Mon Sep 17 00:00:00 2001 From: Adam Monsen Date: Wed, 8 Feb 2023 09:59:23 -0800 Subject: [PATCH] **/entrypoint.sh: use flock instead of a file Note there are no changes to `Dockerfile-alpine.template`. We thought we needed `util-linux` for `flock`, but we don't. Busybox includes `flock`, and this command is compatible with GNU `flock` for our use case (I tested it with `flock -n 9`, etc). Signed-off-by: Adam Monsen --- 23/apache/entrypoint.sh | 13 +++++-------- 23/fpm-alpine/entrypoint.sh | 13 +++++-------- 23/fpm/entrypoint.sh | 13 +++++-------- 24/apache/entrypoint.sh | 13 +++++-------- 24/fpm-alpine/entrypoint.sh | 13 +++++-------- 24/fpm/entrypoint.sh | 13 +++++-------- 25/apache/entrypoint.sh | 13 +++++-------- 25/fpm-alpine/entrypoint.sh | 13 +++++-------- 25/fpm/entrypoint.sh | 13 +++++-------- 9 files changed, 45 insertions(+), 72 deletions(-) diff --git a/23/apache/entrypoint.sh b/23/apache/entrypoint.sh index 3175361f..39e53517 100755 --- a/23/apache/entrypoint.sh +++ b/23/apache/entrypoint.sh @@ -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 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)) @@ -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 @@ -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/www/html/nextcloud-init-sync.lock fi # Update htaccess after init if requested diff --git a/23/fpm-alpine/entrypoint.sh b/23/fpm-alpine/entrypoint.sh index 3175361f..39e53517 100755 --- a/23/fpm-alpine/entrypoint.sh +++ b/23/fpm-alpine/entrypoint.sh @@ -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 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)) @@ -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 @@ -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/www/html/nextcloud-init-sync.lock fi # Update htaccess after init if requested diff --git a/23/fpm/entrypoint.sh b/23/fpm/entrypoint.sh index 3175361f..39e53517 100755 --- a/23/fpm/entrypoint.sh +++ b/23/fpm/entrypoint.sh @@ -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 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)) @@ -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 @@ -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/www/html/nextcloud-init-sync.lock fi # Update htaccess after init if requested diff --git a/24/apache/entrypoint.sh b/24/apache/entrypoint.sh index 3175361f..39e53517 100755 --- a/24/apache/entrypoint.sh +++ b/24/apache/entrypoint.sh @@ -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 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)) @@ -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 @@ -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/www/html/nextcloud-init-sync.lock fi # Update htaccess after init if requested diff --git a/24/fpm-alpine/entrypoint.sh b/24/fpm-alpine/entrypoint.sh index 3175361f..39e53517 100755 --- a/24/fpm-alpine/entrypoint.sh +++ b/24/fpm-alpine/entrypoint.sh @@ -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 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)) @@ -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 @@ -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/www/html/nextcloud-init-sync.lock fi # Update htaccess after init if requested diff --git a/24/fpm/entrypoint.sh b/24/fpm/entrypoint.sh index 3175361f..39e53517 100755 --- a/24/fpm/entrypoint.sh +++ b/24/fpm/entrypoint.sh @@ -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 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)) @@ -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 @@ -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/www/html/nextcloud-init-sync.lock fi # Update htaccess after init if requested diff --git a/25/apache/entrypoint.sh b/25/apache/entrypoint.sh index 3175361f..39e53517 100755 --- a/25/apache/entrypoint.sh +++ b/25/apache/entrypoint.sh @@ -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 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)) @@ -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 @@ -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/www/html/nextcloud-init-sync.lock fi # Update htaccess after init if requested diff --git a/25/fpm-alpine/entrypoint.sh b/25/fpm-alpine/entrypoint.sh index 3175361f..39e53517 100755 --- a/25/fpm-alpine/entrypoint.sh +++ b/25/fpm-alpine/entrypoint.sh @@ -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 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)) @@ -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 @@ -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/www/html/nextcloud-init-sync.lock fi # Update htaccess after init if requested diff --git a/25/fpm/entrypoint.sh b/25/fpm/entrypoint.sh index 3175361f..39e53517 100755 --- a/25/fpm/entrypoint.sh +++ b/25/fpm/entrypoint.sh @@ -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 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)) @@ -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 @@ -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/www/html/nextcloud-init-sync.lock fi # Update htaccess after init if requested