Tuesday, December 24, 2024

script – The best way to often restart bitcoind after some time frame on Linux

The bitcoind course of exits nearly instantly once you run bitcoind-cli cease so you can not merely detect the bitcoind course of. Despite the fact that you may probably see bitcoind with htop after operating bitcoin-cli cease you can not see it with ps as a result of it has exited.

The reply is to discover a approach to reliably look forward to the method cache to complete writing to disk. bitcoind properly writes to debug log with the next message as the very last thing it sends to disk, Shutdown: performed so it’s potential to detect this manner.

The next script is obtainable on GitHub on the MIT Licence and is republished right here with permission below the extra licences of.

I Hope it’s helpful for you.

#!/bin/bash
# Exit and restart bitcoind after a while interval
# Willtech ©2022

# How typically to restart in seconds
timeout=3600

# BAT / CMD goto operate
# Supply: https://www.codegrepper.com/code-examples/shell/bash+bounce+to
operate goto
{
    label=$1
    cmd=$(sed -n "/^:[[:blank:]][[:blank:]]*${label}/{:a;n;p;ba};" $0 | 
          grep -v ':$')
    eval "$cmd"
    exit
}
# Only for the heck of it: the way to create a variable the place to leap to:
begin=${1:-"begin"}
goto "$begin"

: begin

#Begin bitcoind
bitcoind -daemon

#Run till timout
sleep $timeout

#Cease bitcoind
bitcoin-cli cease

#Tries for ten minutes to see if exit is detected.
till timeout 600s tail -f /media/drive2/.bitcoin/debug.log | grep -m 1 "Shutdown: performed"
  do
    sleep 2
  performed

#Log once more
echo once more

#Loop to : begin
goto "begin"

echo bar

# Ref >>>
## https://askubuntu.com/a/1070296
## https://www.delftstack.com/howto/linux/bash-goto/

Anecdotally, it used to take perhaps a month with 1TB USB3 platter disk to do preliminary sync even with swap as bigger than 100GB however now it takes solely about three days restarting each one hour till it’s updated. That’s in blocks obtain mode on a clean disk in order that knowledge is written close to to the place it’s discovered.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles