do not stuck when cloning already mirrored repository v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 21 Apr 2019 21:49:35 +0200
branchv_0
changeset 127bdf24cc2e9e
parent 11 d46ed3f5c72b
child 13 a0b7d78460c2
do not stuck when cloning already mirrored repository
vcs-backup.sh
     1.1 --- a/vcs-backup.sh	Sun Apr 21 00:05:19 2019 +0200
     1.2 +++ b/vcs-backup.sh	Sun Apr 21 21:49:35 2019 +0200
     1.3 @@ -106,7 +106,6 @@
     1.4  		echo "submited" > "$absolutePath/state.txt"
     1.5  		setfacl -m u:${VCS_BACKUP_USER}:r  "$absolutePath/url.txt"
     1.6  		setfacl -m u:${VCS_BACKUP_USER}:rw "$absolutePath/state.txt"
     1.7 -		echo "$relativePath" | socat -u - unix-send:${VCS_BACKUP_SUBVOLUME_SOCKET};
     1.8  
     1.9  		if [[ "$3" == "public" ]]; then
    1.10  			cd "$VCS_BACKUP_PUBLIC_DIR";
    1.11 @@ -115,9 +114,18 @@
    1.12  		fi
    1.13  
    1.14  		if [[ "$4" == "clone" ]]; then
    1.15 -			socat -u "unix-recvfrom:$absolutePath/${VCS_BACKUP_CLONE_CALLBACK_SOCKET},mode=777" - | while read m; do # TODO: ,group=${VCS_BACKUP_USER} and no 777
    1.16 -				echo "Message from the clone service: $m";
    1.17 -			done;
    1.18 +			callBackSocket=$absolutePath/${VCS_BACKUP_CLONE_CALLBACK_SOCKET}
    1.19 +			socat -u "unix-recvfrom:$callBackSocket,mode=777" - | while read m; do # TODO: ,group=${VCS_BACKUP_USER} and no 777 ?
    1.20 +				echo "Message from the service: $m";
    1.21 +			done &
    1.22 +			callBackPID=$!;
    1.23 +		fi
    1.24 +
    1.25 +		echo "$relativePath" | socat -u - unix-send:${VCS_BACKUP_SUBVOLUME_SOCKET};
    1.26 +
    1.27 +		if [[ "$4" == "clone" ]]; then
    1.28 +			echo "Waiting for a message from the service on $callBackSocket (PID $callBackPID)";
    1.29 +			wait -n $callBackPID;
    1.30  		fi
    1.31  	else
    1.32  		echo "Unsupported VCS type: '$1' or URL: '$2'" >&2;
    1.33 @@ -133,10 +141,17 @@
    1.34  vcs_backup_public_serverStartSubvolumeService() {
    1.35  	socat -u "unix-recv:${VCS_BACKUP_SUBVOLUME_SOCKET},group=${VCS_BACKUP_MANAGER},mode=770" - | while read d; do
    1.36  		mkdir -p $(dirname "$VCS_BACKUP_CURRENT_DIR/$d");
    1.37 -		btrfs subvolume create "$VCS_BACKUP_CURRENT_DIR/$d" && \
    1.38 -		echo "subvolumeCreated" > "$VCS_BACKUP_CONFIG_DIR/$d/state.txt" && \
    1.39 -		chown "${VCS_BACKUP_USER}:${VCS_BACKUP_USER}" "$VCS_BACKUP_CURRENT_DIR/$d" && \
    1.40 -		echo "$d" | socat -u - unix-send:${VCS_BACKUP_CLONE_SOCKET};
    1.41 +		if [[ -e "$VCS_BACKUP_CURRENT_DIR/$d" ]]; then
    1.42 +			callBackSocket="$VCS_BACKUP_CONFIG_DIR/$d/$VCS_BACKUP_CLONE_CALLBACK_SOCKET";
    1.43 +			if [[ -e "$callBackSocket" ]]; then
    1.44 +				echo "alreadyDone" | socat -u - unix-send:"$callBackSocket";
    1.45 +			fi
    1.46 +		else
    1.47 +			btrfs subvolume create "$VCS_BACKUP_CURRENT_DIR/$d" && \
    1.48 +			echo "subvolumeCreated" > "$VCS_BACKUP_CONFIG_DIR/$d/state.txt" && \
    1.49 +			chown "${VCS_BACKUP_USER}:${VCS_BACKUP_USER}" "$VCS_BACKUP_CURRENT_DIR/$d" && \
    1.50 +			echo "$d" | socat -u - unix-send:${VCS_BACKUP_CLONE_SOCKET};
    1.51 +		fi
    1.52  	done
    1.53  }
    1.54