solve conflicts with multiple parallel ctorrents
This commit is contained in:
		
							parent
							
								
									7d7301f67d
								
							
						
					
					
						commit
						2078fab902
					
				
					 1 changed files with 30 additions and 5 deletions
				
			
		| 
						 | 
					@ -23,14 +23,39 @@ download_image() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
torrent_image() {
 | 
					torrent_image() {
 | 
				
			||||||
    if [[ -f "/lmn/vm/${VM_NAME}.qcow2.torrent" ]]; then
 | 
					    if [[ ! -f "/lmn/vm/${VM_NAME}.qcow2.torrent" ]]; then
 | 
				
			||||||
      cd /lmn/vm
 | 
					 | 
				
			||||||
      ctorrent -e 0 "${VM_NAME}.qcow2.torrent"
 | 
					 | 
				
			||||||
      /usr/local/bin/vmimage-torrent restart "${VM_NAME}.qcow2"
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
      echo "No torrent-File found"
 | 
					      echo "No torrent-File found"
 | 
				
			||||||
      exit 1
 | 
					      exit 1
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					    lockfile="/tmp/sync-vm-${VM_NAME}.lock"
 | 
				
			||||||
 | 
					    if ! flock -n "$lockfile" echo "try to acquire lock"; then
 | 
				
			||||||
 | 
					      echo torrent seems to be in process.
 | 
				
			||||||
 | 
					      echo waiting for completion ...
 | 
				
			||||||
 | 
					      flock -w 3600 "$lockfile" echo "...completed"
 | 
				
			||||||
 | 
					      sleep 5
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      (
 | 
				
			||||||
 | 
					        if ! flock -n 200; then
 | 
				
			||||||
 | 
						  echo "failed to acquire lock"
 | 
				
			||||||
 | 
						  echo "Bitte noch einmal starten."
 | 
				
			||||||
 | 
					          echo "Beliebige Taste zum Beenden."
 | 
				
			||||||
 | 
						  read -n 1
 | 
				
			||||||
 | 
						  exit 1
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					        torrent="${VM_NAME}.qcow2.torrent"
 | 
				
			||||||
 | 
					        session="${torrent//./_}"
 | 
				
			||||||
 | 
					        if vmimage-torrent status | grep -qw ^"$session"; then
 | 
				
			||||||
 | 
					          vmimage-torrent stop "${VM_NAME}.qcow2"
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					        cd /lmn/vm
 | 
				
			||||||
 | 
					        ctorrent -e 0 "${VM_NAME}.qcow2.torrent"
 | 
				
			||||||
 | 
					        /usr/local/bin/vmimage-torrent restart "${VM_NAME}.qcow2"
 | 
				
			||||||
 | 
					        if ! flock -u 200; then
 | 
				
			||||||
 | 
						  echo failed to drop lock
 | 
				
			||||||
 | 
						  exit 1
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					      ) 200>"$lockfile"
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sync_all_images() {
 | 
					sync_all_images() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue