diff --git a/crowdbunker.sh b/crowdbunker.sh index bbbc217..799cc54 100755 --- a/crowdbunker.sh +++ b/crowdbunker.sh @@ -14,7 +14,11 @@ MY_PATH="`dirname \"$0\"`" # relative MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized ME="${0##*/}" countMErunning=$(ps auxf --sort=+utime | grep -w "$ME" | grep -v -E 'color=auto|grep' | wc -l) -[[ $countMErunning -gt 2 ]] && echo "$ME already running. EXIT." && exit 0 +[[ $countMErunning -gt 2 ]] && \ + echo "$ME already running. Killing old process" && \ + mekill==$(ps auxf --sort=+utime | grep -w "$ME" | grep -v -E 'color=auto|grep' | head -n 1 | awk '{ print $2 }') && \ + kill -9 $mekill && \ + exit 0 TS=$(date -u +%s%N | cut -b1-13) MOATS=$(date -u +"%Y%m%d%H%M%S%4N") @@ -23,7 +27,16 @@ MOATS=$(date -u +"%Y%m%d%H%M%S%4N") YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) || echo " warning ipfs daemon not running" isLAN=$(hostname -I | awk '{print $1}' | head -n 1 | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") -IPFSNODEID=$(cat ~/.ipfs/config | jq -r .Identity.PeerID) +IPFSNODEID=$(ipfs id --timeout=1s | jq -r .ID) +howmany=$(cat /tmp/ipfsbunk.timeout) +if [[ ! $IPFSNODEID ]]; then + ## wait a howmany timeout before restarting ipfs + howmany=$((howmany + 1)) && echo $howmany > /tmp/ipfsbunk.timeout + [ $howmany -gt 3 ] && [[ -f /etc/sudoers.d/systemctl ]] && echo "IPFS NOT RUNNING $(date)" && rm /tmp/ipfsbunk.timeout && sudo systemctl stop ipfs && rm /config/ipfs/repo.lock && sudo systemctl start ipfs + exit 1 +else + echo 0 > /tmp/ipfsbunk.timeout +fi IPFSNGW="https://tube.copylaradio.com" IPFSNGW="http://127.0.0.1:8080"