Browse Source

removed torrent backup seeding

v1.3
Christian Rotzoll 6 years ago
parent
commit
3cf4d6e867
  1. 21
      home.admin/00infoBlitz.sh
  2. 121
      home.admin/50torrentHDD.sh
  3. 84
      home.admin/_background.sh
  4. 8
      home.admin/_bootstrap.provision.sh

21
home.admin/00infoBlitz.sh

@ -281,25 +281,6 @@ else
fi
fi
# STATUS SINALING: Backup Torrent Seeding
torrentBaseStatus=""
torrentUpdateStatus=""
if [ "${backupTorrentSeeding}" == "on" ]; then
torrentBaseStatus="•"
torrentUpdateStatus="•"
source <(sudo -u admin /home/admin/50torrentHDD.sh status)
if [ "${baseComplete}" == "1" ]; then
torrentBaseStatus="↑"
elif [ "${baseSeeding}" == "1" ]; then
torrentBaseStatus="↓"
fi
if [ "${updateComplete}" == "1" ]; then
torrentUpdateStatus="↑"
elif [ "${updateSeeding}" == "1" ]; then
torrentUpdateStatus="↓"
fi
fi
sleep 5
printf "
${color_yellow}
@ -312,7 +293,7 @@ ${color_yellow} ,'/ ${color_gray}%s, temp %s°C %s°F
${color_yellow} ,' / ${color_gray}Free Mem ${color_ram}${ram} ${color_gray} HDDuse ${color_hdd}%s${color_gray}
${color_yellow} ,' /_____, ${color_gray}ssh admin@${color_green}${local_ip}${color_gray}${network_rx}${network_tx}
${color_yellow} .'____ ,' ${color_gray}${webinterfaceInfo}
${color_yellow} / ,' ${color_gray}${network} ${color_green}${networkVersion} ${chain}net ${color_gray}Sync ${sync_color}${sync} %s${torrentBaseStatus}${torrentUpdateStatus}
${color_yellow} / ,' ${color_gray}${network} ${color_green}${networkVersion} ${chain}net ${color_gray}Sync ${sync_color}${sync} %s
${color_yellow} / ,' ${color_gray}${public_addr_pre}${public_color}${public_addr} ${public}${networkConnectionsInfo}
${color_yellow} /,' ${color_gray}
${color_yellow} /' ${color_gray}LND ${color_green}${ln_version} ${ln_baseInfo}

121
home.admin/50torrentHDD.sh

@ -1,19 +1,4 @@
#!/bin/bash
# POSSOBLE PARAMETERS:
# backup-torrent-hosting
# to just kick of the torrent downloads in the background during
# regular RaspiBlitz running. So you support torrent hosting and have a blockchain backup ready just in case.
# cleanup
# to stop background torrents and clean up
# status
# to get info backround torrent hosting
# stop
# just stopping the download - not switching off
## get basic info
source /home/admin/raspiblitz.info
@ -22,10 +7,8 @@ source /home/admin/raspiblitz.info
# in directory /home.admin/assets/
# WITHOUT THE '.torrent' ENDING
#bitcoinBase="raspiblitz-bitcoin1-2018-10-13-base"
#bitcoinUpdate="raspiblitz-bitcoin1-2019-04-09-update"
# taken from https://getbitcoinblockchain.com/
# TODO later first try to download from that website and have local torrent files for backup
# using https://getbitcoinblockchain.com/ as abase
# and make my own upt-to-date update file becuase they dont do that anymore
bitcoinBase="raspiblitz-bitcoin2-2019-05-01-base"
bitcoinUpdate="raspiblitz-bitcoin2-2019-06-29-update"
@ -46,63 +29,6 @@ echo "updateTorrent='${updateTorrentFile}'"
targetDir="/mnt/hdd/torrent"
sessionDir="/home/admin/.rtorrent.session"
# BACKUP TORRENT SEEDING
if [ "$1" == "stop" ] || [ "$1" == "cleanup" ]; then
echo "Stopping Torrents ..."
sessionPID=$(screen -ls | grep "blockchain" | cut -d "." -f1 | xargs)
if [ ${#sessionPID} -gt 0 ]; then
sudo pkill -P ${sessionPID}
fi
sessionPID=$(screen -ls | grep "update" | cut -d "." -f1 | xargs)
if [ ${#sessionPID} -gt 0 ]; then
sudo pkill -P ${sessionPID}
fi
fi
if [ "$1" == "stop" ] || [ "$1" == "cleanup" ]; then
echo "Stopping Torrents ..."
sessionPID=$(screen -ls | grep "blockchain" | cut -d "." -f1 | xargs)
if [ ${#sessionPID} -gt 0 ]; then
sudo pkill -P ${sessionPID}
fi
sessionPID=$(screen -ls | grep "update" | cut -d "." -f1 | xargs)
if [ ${#sessionPID} -gt 0 ]; then
sudo pkill -P ${sessionPID}
fi
if [ "$1" == "stop" ]; then
exit 0
fi
echo "Deleting all possible old (version) torrent data ..."
sudo rm -r /home/admin/.rtorrent.session 2>/dev/null
sudo rm -r /mnt/hdd/torrent 2>/dev/null
echo "Changing config ..."
sudo sed -i "s/^backupTorrentSeeding=.*/backupTorrentSeeding=off/g" /mnt/hdd/raspiblitz.conf
echo "DONE"
exit
fi
if [ "$1" == "status" ]; then
echo "# BASE TORRENT - for details call:"
echo "# screen -S blockchain -X hardcopy .temp.out && cat ./.temp.out && rm ./.temp.out"
sessionPID=$(screen -ls | grep "blockchain" | cut -d "." -f1 | xargs)
if [ ${#sessionPID} -gt 0 ]; then
echo "baseSeeding=1"
else
echo "baseSeeding=0"
fi
torrentComplete=$(cat ${sessionDir}/blockchain/*.torrent.rtorrent 2>/dev/null | grep ':completei1' -c)
echo "baseComplete=${torrentComplete}"
echo "# UPDATE TORRENT - for details call:"
echo "# screen -S update -X hardcopy .temp.out && cat ./.temp.out && rm ./.temp.out"
sessionPID=$(screen -ls | grep "update" | cut -d "." -f1 | xargs)
if [ ${#sessionPID} -gt 0 ]; then
echo "updateSeeding=1"
else
echo "updateSeeding=0"
fi
torrentComplete=$(cat ${sessionDir}/update/*.torrent.rtorrent 2>/dev/null | grep ':completei1' -c)
echo "updateComplete=${torrentComplete}"
exit
fi
# make sure folders exist
sudo mkdir ${sessionDir} 2>/dev/null
sudo mkdir ${targetDir} 2>/dev/null
@ -135,7 +61,7 @@ if [ ${torrentComplete1} -eq 0 ]; then
# start torrent download in screen session
echo "starting torrent: blockchain"
command1="sudo nice -n 10 chrt -r 1 rtorrent -n -p 49200-49250 -d ${targetDir} -s ${sessionDir}/blockchain/ /home/admin/assets/${baseTorrentFile}.torrent"
command1="sudo rtorrent -n -p 49200-49250 -d ${targetDir} -s ${sessionDir}/blockchain/ /home/admin/assets/${baseTorrentFile}.torrent"
screenCommand="screen -S blockchain -L screen.log -dm ${command1}"
echo "${screenCommand}"
bash -c "${screenCommand}"
@ -159,7 +85,7 @@ if [ ${torrentComplete2} -eq 0 ]; then
# start torrent download in screen session
echo "starting torrent: update"
command2="sudo nice -n 10 chrt -r 1 rtorrent -n -p 49200-49250 -d ${targetDir} -s ${sessionDir}/update/ /home/admin/assets/${updateTorrentFile}.torrent"
command2="sudo rtorrent -n -p 49200-49250 -d ${targetDir} -s ${sessionDir}/update/ /home/admin/assets/${updateTorrentFile}.torrent"
screenCommand="screen -S update -L screen.log -dm ${command2}"
echo "${screenCommand}"
bash -c "${screenCommand}"
@ -168,45 +94,6 @@ if [ ${torrentComplete2} -eq 0 ]; then
fi
sleep 2
##############################
# BACKUP TORRENT SEEDING
##############################
# just let torrent start and run in the background
if [ "$1" == "backup-torrent-hosting" ]; then
# changing config - so it can be startup again after a reboot by bootstrap
source /mnt/hdd/raspiblitz.conf
if [ ${#backupTorrentSeeding} -eq 0 ]; then
echo "backupTorrentSeeding=on" >> /mnt/hdd/raspiblitz.conf
else
sudo sed -i "s/^backupTorrentSeeding=.*/backupTorrentSeeding=on/g" /mnt/hdd/raspiblitz.conf
fi
# set the torrents processes to cpulimit 25%
sleep 6
echo ""
rtorrentPIDs=$(ps axf | grep "rtorrent" | awk '{$1=$1;print}' | cut -d' ' -f1)
while read -r pid ; do
ps ${pid} | grep "rtorrent"
echo "---> reducing this rTorrent process to 25% CPU"
sudo cpulimit -p ${pid} -l 25 &
echo ""
done < <(echo "${rtorrentPIDs}")
sleep 6
# set the torrents processes to cpulimit 20%
#sessionPID=$(screen -ls | grep "blockchain" | cut -d "." -f1 | xargs)
#echo "Putting rTorrent blockchain 'BASE' (PID=${sessionPID}) to background ... (please wait)"
#sudo cpulimit -p ${sessionPID} -l 25 &
#sessionPID=$(screen -ls | grep "update" | cut -d "." -f1 | xargs)
#echo "Putting rTorrent blockchain 'UPDATE' (PID=${sessionPID}) to background ... (please wait)"
#sudo cpulimit -p ${sessionPID} -l 25 &
echo "Done BACKUP TORRENT HOSTING"
exit
fi
##############################
# MONITOR PROGRESS
##############################

84
home.admin/_background.sh

@ -22,10 +22,6 @@ fi
echo "_background.sh STARTED"
# monitor lost LND sync
syncedSince=0
lastSyncState=0
counter=0
while [ 1 ]
do
@ -215,86 +211,6 @@ do
fi
fi
###############################
# LND MONITOR LOST SYNC
###############################
# check every 5min
recheckSync=$(($counter % 300))
if [ ${recheckSync} -eq 1 ]; then
source ${configFile}
#echo "LND MONITOR LOST SYNC ..."
lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
#echo "lndSynced(${lndSynced})"
#echo "syncedSince(${syncedSince})"
#echo "lastSyncState(${lastSyncState})"
if [ ${lndSynced} -eq ${lastSyncState} ]; then
echo "no sync change"
if [ ${lndSynced} -eq 1 ]; then
#echo "all is good - LND still in sync now for:"
actualSecondsTimestamp=$(date +%s)
secondsInSync=$(echo "${actualSecondsTimestamp}-"${syncedSince} | bc)
#echo "${secondsInSync} seconds"
# when >10min in sync
if [ ${secondsInSync} -gt 3600 ]; then
#echo "LND in sync for longer then 1 hour"
if [ "${backupTorrentSeeding}" == "on" ]; then
#echo "Backup Torrent Seeding is ON - check if already running"
source <(sudo -u admin /home/admin/50torrentHDD.sh status)
if [ "${baseSeeding}" == "0" ] || [ "${updateSeeding}" == "0" ]; then
echo "---> STARTING Backup Torrent Seeding"
sudo -u admin /home/admin/50torrentHDD.sh backup-torrent-hosting
fi
fi
fi
else
#echo "still not in sync"
if [ ${syncedSince} -gt 0 ]; then
echo "was in sync at least once since rinning but lost now for:"
actualSecondsTimestamp=$(date +%s)
secondsOutOfSync=$(echo "${actualSecondsTimestamp}-"${syncedSince} | bc)
echo "${secondsOutOfSync} seconds"
# when >1h out of sync
#if [ ${secondsOutOfSync} -gt 3600 ]; then
# echo "!!!! LND fell out of sync for longer then 1 hour !!!"
# TODO: When auto-unlock is ON --> consider implementing restart (this sometimes help)
#fi
fi
fi
else
echo "sync change detected"
if [ ${lastSyncState} -eq 1 ] && [ ${lndSynced} -eq 0 ]; then
echo "--> LND SYNC LOST"
if [ "${backupTorrentSeeding}" == "on" ]; then
#echo "Backup Torrent Seeding is ON - check if still running"
source <(sudo -u admin /home/admin/50torrentHDD.sh status)
if [ "${baseSeeding}" == "1" ] || [ "${updateSeeding}" == "1" ]; then
echo "---> STOPPING Backup Torrent Seeding"
sudo -u admin /home/admin/50torrentHDD.sh stop
fi
fi
else
if [ ${syncedSince} -eq 0 ]; then
echo "--> LND SYNC GAINED"
else
echo "--> LND SYNC RECOVERED"
fi
syncedSince=$(date +%s)
fi
fi
lastSyncState=${lndSynced}
fi
###############################
# LND AUTO-UNLOCK
###############################

8
home.admin/_bootstrap.provision.sh

@ -216,14 +216,6 @@ else
echo "Provisioning SSH Tunnel - not active" >> ${logFile}
fi
# BACKUP TORRENT HOSTING
if [ "${backupTorrentHosting}" == "on" ]; then
echo "Backup Torrent Hosting - clean up possible old torrent data" >> ${logFile}
sudo /home/admin/50torrentHDD.sh backup-torrent-hosting-cleanup
else
echo "Backup Torrent Hosting - not active" >> ${logFile}
fi
# replay backup LND conf & tlscerts
# https://github.com/rootzoll/raspiblitz/issues/324
echo "" >> ${logFile}

Loading…
Cancel
Save