Skip to content

Instantly share code, notes, and snippets.

@tmuskal
Created October 16, 2018 04:46
Show Gist options
  • Save tmuskal/2b031ccffe3c1b8a805cb09f5732240e to your computer and use it in GitHub Desktop.
Save tmuskal/2b031ccffe3c1b8a805cb09f5732240e to your computer and use it in GitHub Desktop.
wait till after your schedule and kill your BP
#!/bin/bash
PRODUCERS_ORDER=`cleos get schedule | head -n 24 | tail -n 21 | cut -d " " -f 5`
PID=`ps -a | grep nodeos | cut -f 1 -d " "`
MYPROD=$1
PASSED_BEFORE=0
# todo: handle case you are the last one in schedule, wait for first one in schedule to kill
while true
do
WHOISPRODUCING=`sudo timeout 1s strace -fp$PID -s9999 -e trace=write 2>&1 | grep -o '".\+[^"]"' | grep on_incoming_block | cut -d " " -f 25 | tail -n 1`
echo $WHOISPRODUCING
if [[ "$PASSED_BEFORE" == "0" ]]
then
if [[ "$WHOISPRODUCING" < "$MYPROD" ]]
then
echo before your turn
PASSED_BEFORE=1
else
if [[ "$WHOISPRODUCING" == "$1" ]]
then
echo currently producing. not killing now
PASSED_BEFORE=1
else
echo waiting for schedule start
fi
fi
else
if [[ "$WHOISPRODUCING" > "$MYPROD" ]]
then
echo after your turn. killing now
break
fi
fi
done
#kill -9 $PID
sleep 10
secs=$((90))
while [ $secs -gt 0 ]; do
PID=`ps -a | grep nodeos | cut -f 1 -d " "`
if [[ "$PID" == "" ]]
then
echo -ne "$secs to revive process\033[0K\r"
else
echo found revived process
break;
fi
sleep 1
: $((secs--))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment