Very Secure

Scheduled Defibrillation For The Jalopy That is TRB

A couple of months ago I was unable to start my car. So I used a trick a mechanic taught me - I opened the hood and banged on the starter with a hammer. I then turned the key in the ignition, but the car still wouldn't start. I tried again, this time banging on the starter harder. And voila, it worked. I had to do this routine of banging on the starter with a hammer1 every time i wanted to use my car. But eventually something got bumped into the right position, I guess, because I no longer have to do this absurd routine to start my car.

It seems that the same type of bang-it-till-it-works approach is required to get trb running. I have restarted my node countless times in order to get it unstuck during the sync process. So I'm posting an example shell script that kills and then restarts trb's bitcoind.2 With the current state of trb, a script like this running on a crontask every 24 hours seems ~required to get sync'd in a timely fashion.3

restart_trb.sh

pid=`top -n 1 -b | grep "bitcoind" | awk '{print $1}';`
echo "killing bitcoind with pid $pid";
kill $pid;
echo "sleeping 60s";
sleep 60;
echo "force killing bitcoind"
kill -9 $pid;
sleep 60;
echo "sleeping another 30s";
# Change IPs and home path accordingly.
LC_ALL=C /your/raw/path/to/bitcoind -daemon -logtimestamps -myip=205.134.172.28 -connect=205.134.172.27 -connect=54.39.156.17 -connect=143.202.160.10 -verifyall &

The script works as follows. First it snags the pid of the process by piping the results from top into grep. If bitcoind is not running then the $pid variable is going to be empty and the following kill commands will fail. Otherwise, as per asciilifeform's advice, the script first does a normal kill to the bitcoind process. This should shutdown bitcoind "gracefully" so that there is no interrupted write to the db, or what have you. However, normal kill's often fail to stop bitcoind, so the script follows up with a kill -9. Finally, the script starts trb.

A potential improvement to this script would be to add some code that handles a corrupted db.

  1. the starter starter! []
  2. You have to change the last line that starts trb to meet the requirements of your specific environment. []
  3. aka less than three months. []

Leave a Reply