Author

Topic: Bitcoind starts at reboot but RPC calls wont work (Read 446 times)

hero member
Activity: 544
Merit: 507
November 02, 2017, 03:22:38 AM
#9
Great that it works, but we don't know why ...   Huh
When you have the delay included, it would be good to know what happens immedeatly at startup, and what happens after the delay...
Is it maybe that the network stack initializes after the crontabs of the users?
Is it on a DHCP network, and hasn't received an IP yet?

well, I guess you are happy that it runs, and further research might not be required  Grin Grin Grin
happy bitcoining!

indeed I am not just happy to have this fixed but also I would like to know what happens.

I bet a dmesg analysis would answer our questions. It was definitely that crontab is executed before the IP assigning.

It is a shame I dont know too much about this error

Code:
Binding RPC on address 127.0.0.1 port 8332 failed.
sr. member
Activity: 257
Merit: 343
Great that it works, but we don't know why ...   Huh
When you have the delay included, it would be good to know what happens immedeatly at startup, and what happens after the delay...
Is it maybe that the network stack initializes after the crontabs of the users?
Is it on a DHCP network, and hasn't received an IP yet?

well, I guess you are happy that it runs, and further research might not be required  Grin Grin Grin
happy bitcoining!
hero member
Activity: 544
Merit: 507
same topic mentioned here - we are reading both :-)
https://bitcoin.stackexchange.com/questions/61617/bitcoind-start-at-reboot-but-rpc-calls-wont-work?noredirect=1#comment70887_61617

you may want to try a shell script, that is executed by your crontab.
Save this file as bitcoind.sh, and place it anywhere (I usually through this in /usr/local/bin, which is in the $PATH, then you don't need fully qualified filename).
In your crontab you simply write: @reboot bitcoin.sh
no ampersand (&) would be required, cause bitcoind is launched as daemon. I think I remember that bitcoind has an option to provide a parameter for the config file, this might also help.

Code:
#!/bin/sh
PATH=$PATH:/home/pine:/usr/local/bin
cd /home/pine
bitcoind -daemon

I did a test on my RasPi2 with SuSE armv7 Linux 4.1.19-1-rpi2. There it works easily from scratch. Just entered "@reboot bitcoind -daemon" for the user who normally runs bitcoin. And then I can execute commands with bitcoin-cli. No problem.

One observation:
When I reboot, my Raspberry has no real time clock, so the bitcoind would complain, that system time is older than last entries in blockchain, and hence it cannot start. - you may want  to check, if your system (when disconnected from network) comes up with a time in 1970... If so, I would have a workaround.

What is your syslog saying?
Not sure, what you have, maybe "tail -n50 -f /var/log/messages" or newer systems have "journalctl -f --since=-5min"...
If still no clue, one could compare the list of open files (lsof -p ).

Happy testing!

hey hello there! thank you for your time and help. I found out I had to add the sleep command to the crontab line.

It was my mistake to not add the debug.log into the stack exchange question. I will add it later and then reply the answer.

peace
hero member
Activity: 544
Merit: 507
Will point out the obvious and say that this is likely to be the cause of your issue regarding RPC:


Code:
2017-11-01 18:43:50 libevent: getaddrinfo: address family for nodename not supported
2017-11-01 18:43:50 Binding RPC on address 127.0.0.1 port 8332 failed.
It would appear that on reboot, with the cron, that bitcoind is starting up and attempting to bind the RPC stuff before some required service(s) have been initialised properly.

Maybe you need a delay, to give these services time to start up BEFORE bitcoind tries to bind RPC.

Maybe something like:
Code:
@reboot /bin/sleep 120 ; /usr/local/bin/bitcoind &
To give it a 2 minute (120 second) pause before starting bitcoind... You can always increase our reduce the delay time as required.

Hello, I have added to the crontab line the sleep instruction and IT IS WORKING NOW!! Cheesy

Thank you very much dear Sir!
HCP
legendary
Activity: 2086
Merit: 4361
Will point out the obvious and say that this is likely to be the cause of your issue regarding RPC:


Code:
2017-11-01 18:43:50 libevent: getaddrinfo: address family for nodename not supported
2017-11-01 18:43:50 Binding RPC on address 127.0.0.1 port 8332 failed.
It would appear that on reboot, with the cron, that bitcoind is starting up and attempting to bind the RPC stuff before some required service(s) have been initialised properly.

Maybe you need a delay, to give these services time to start up BEFORE bitcoind tries to bind RPC.

Maybe something like:
Code:
@reboot /bin/sleep 120 ; /usr/local/bin/bitcoind &
To give it a 2 minute (120 second) pause before starting bitcoind... You can always increase our reduce the delay time as required.
sr. member
Activity: 257
Merit: 343
same topic mentioned here - we are reading both :-)
https://bitcoin.stackexchange.com/questions/61617/bitcoind-start-at-reboot-but-rpc-calls-wont-work?noredirect=1#comment70887_61617

you may want to try a shell script, that is executed by your crontab.
Save this file as bitcoind.sh, and place it anywhere (I usually through this in /usr/local/bin, which is in the $PATH, then you don't need fully qualified filename).
In your crontab you simply write: @reboot bitcoin.sh
no ampersand (&) would be required, cause bitcoind is launched as daemon. I think I remember that bitcoind has an option to provide a parameter for the config file, this might also help.

Code:
#!/bin/sh
PATH=$PATH:/home/pine:/usr/local/bin
cd /home/pine
bitcoind -daemon

I did a test on my RasPi2 with SuSE armv7 Linux 4.1.19-1-rpi2. There it works easily from scratch. Just entered "@reboot bitcoind -daemon" for the user who normally runs bitcoin. And then I can execute commands with bitcoin-cli. No problem.

One observation:
When I reboot, my Raspberry has no real time clock, so the bitcoind would complain, that system time is older than last entries in blockchain, and hence it cannot start. - you may want  to check, if your system (when disconnected from network) comes up with a time in 1970... If so, I would have a workaround.

What is your syslog saying?
Not sure, what you have, maybe "tail -n50 -f /var/log/messages" or newer systems have "journalctl -f --since=-5min"...
If still no clue, one could compare the list of open files (lsof -p ).

Happy testing!
hero member
Activity: 544
Merit: 507
Add -daemon to the crontab command or add daemon=1 to your bitcoin.conf file.

all right, I have just added daemon=1 to my bitcoin.conf file , stopped bitcoind and then reboot.

bitcoind started at start up but when I do RPC calls. Still fails
Code:
pine@pine64:~$ bitcoin-cli getnetworkinfo
error: couldn't connect to server: unknown (code -1)
(make sure server is running and you are connecting to the correct RPC port)

This is debug.log when bitcoind starts after rebooting

Code:
2017-11-01 18:43:49 Bitcoin version v0.15.0.1
2017-11-01 18:43:49 InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1
2017-11-01 18:43:49 Assuming ancestors of block 0000000000000000003b9ce759c2a087d52abc4266f8f4ebd6d768b89defa50a have valid signatures.
2017-11-01 18:43:49 Prune configured to target 1000MiB on disk for block and undo files.
2017-11-01 18:43:49 Using the 'standard' SHA256 implementation
2017-11-01 18:43:50 Default data directory /home/pine/.bitcoin
2017-11-01 18:43:50 Using data directory /home/pine/.bitcoin
2017-11-01 18:43:50 Using config file /home/pine/.bitcoin/bitcoin.conf
2017-11-01 18:43:50 Using at most 125 automatic connections (1024 file descriptors available)
2017-11-01 18:43:50 Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements
2017-11-01 18:43:50 Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements
2017-11-01 18:43:50 Using 4 threads for script verification
2017-11-01 18:43:50 scheduler thread start
2017-11-01 18:43:50 libevent: getaddrinfo: address family for nodename not supported
2017-11-01 18:43:50 Binding RPC on address 127.0.0.1 port 8332 failed.
2017-11-01 18:43:50 HTTP: creating work queue of depth 16
2017-11-01 18:43:50 No rpcpassword set - using random cookie authentication
2017-11-01 18:43:50 Generated RPC authentication cookie /home/pine/.bitcoin/.cookie
2017-11-01 18:43:50 HTTP: starting 4 worker threads
2017-11-01 18:43:50 init message: Verifying wallet(s)...
2017-11-01 18:43:50 Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
2017-11-01 18:43:50 Using wallet wallet.dat
2017-11-01 18:43:50 CDBEnv::Open: LogDir=/home/pine/.bitcoin/database ErrorFile=/home/pine/.bitcoin/db.log
2017-11-01 18:43:50 Cache configuration:
2017-11-01 18:43:50 * Using 2.0MiB for block index database
2017-11-01 18:43:50 * Using 8.0MiB for chain state database
2017-11-01 18:43:50 * Using 440.0MiB for in-memory UTXO set (plus up to 286.1MiB of unused mempool space)
2017-11-01 18:43:50 init message: Loading block index...
2017-11-01 18:43:50 Opening LevelDB in /home/pine/.bitcoin/blocks/index
2017-11-01 18:43:50 Opened LevelDB successfully
2017-11-01 18:43:50 Using obfuscation key for /home/pine/.bitcoin/blocks/index: 0000000000000000
2017-11-01 18:44:19 LoadBlockIndexDB: last block file = 1048
2017-11-01 18:44:19 LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=107, size=111768957, heights=492573...492679, time=2017-11-01...2017
-11-01)
2017-11-01 18:44:19 Checking all blk files are present...
2017-11-01 18:44:20 LoadBlockIndexDB(): Block files have previously been pruned
2017-11-01 18:44:20 LoadBlockIndexDB: transaction index disabled
2017-11-01 18:44:20 Opening LevelDB in /home/pine/.bitcoin/chainstate
2017-11-01 18:44:20 Opened LevelDB successfully
2017-11-01 18:44:20 Using obfuscation key for /home/pine/.bitcoin/chainstate: db194782ffd1a6ff
2017-11-01 18:44:20 Loaded best chain: hashBestChain=000000000000000000a3b09f990d5ac691d7f980c5641e1621144f9360482b13 height=492679 date=2017-11-01 18:31:14 progress=0.999991

This is debug.log when I boot the pine64 and then execute bitcoind -daemon

Code:
2017-11-01 18:47:46 Bitcoin version v0.15.0.1
2017-11-01 18:47:46 InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1
2017-11-01 18:47:46 Assuming ancestors of block 0000000000000000003b9ce759c2a087d52abc4266f8f4ebd6d768b89defa50a have valid signatures.
2017-11-01 18:47:46 Prune configured to target 1000MiB on disk for block and undo files.
2017-11-01 18:47:46 Using the 'standard' SHA256 implementation
2017-11-01 18:47:47 Default data directory /home/pine/.bitcoin
2017-11-01 18:47:47 Using data directory /home/pine/.bitcoin
2017-11-01 18:47:47 Using config file /home/pine/.bitcoin/bitcoin.conf
2017-11-01 18:47:47 Using at most 125 automatic connections (1024 file descriptors available)
2017-11-01 18:47:47 Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements
2017-11-01 18:47:47 Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements
2017-11-01 18:47:47 Using 4 threads for script verification
2017-11-01 18:47:47 scheduler thread start
2017-11-01 18:47:47 HTTP: creating work queue of depth 16
2017-11-01 18:47:47 No rpcpassword set - using random cookie authentication
2017-11-01 18:47:47 Generated RPC authentication cookie /home/pine/.bitcoin/.cookie
2017-11-01 18:47:47 HTTP: starting 4 worker threads
2017-11-01 18:47:47 init message: Verifying wallet(s)...
2017-11-01 18:47:47 Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
2017-11-01 18:47:47 Using wallet wallet.dat
2017-11-01 18:47:47 CDBEnv::Open: LogDir=/home/pine/.bitcoin/database ErrorFile=/home/pine/.bitcoin/db.log
2017-11-01 18:47:47 Cache configuration:
2017-11-01 18:47:47 * Using 2.0MiB for block index database
2017-11-01 18:47:47 * Using 8.0MiB for chain state database
2017-11-01 18:47:47 * Using 440.0MiB for in-memory UTXO set (plus up to 286.1MiB of unused mempool space)
2017-11-01 18:47:47 init message: Loading block index...
2017-11-01 18:47:47 Opening LevelDB in /home/pine/.bitcoin/blocks/index
2017-11-01 18:47:47 Opened LevelDB successfully
2017-11-01 18:47:47 Using obfuscation key for /home/pine/.bitcoin/blocks/index: 0000000000000000
2017-11-01 18:48:10 LoadBlockIndexDB: last block file = 1048
2017-11-01 18:48:10 LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=108, size=112816613, heights=492573...492680, time=2017-11-01...2017
-11-01)
2017-11-01 18:48:10 Checking all blk files are present...
2017-11-01 18:48:10 LoadBlockIndexDB(): Block files have previously been pruned
2017-11-01 18:48:10 LoadBlockIndexDB: transaction index disabled
2017-11-01 18:48:10 Opening LevelDB in /home/pine/.bitcoin/chainstate
2017-11-01 18:48:11 Opened LevelDB successfully
2017-11-01 18:48:11 Using obfuscation key for /home/pine/.bitcoin/chainstate: db194782ffd1a6ff
2017-11-01 18:48:11 Loaded best chain: hashBestChain=000000000000000000bed43c3db6a0112a83d89a4ed3f605c2e04544fb0e69ef height=492680 date=2017-11-01 18:45:08 progress=0.999998
staff
Activity: 3458
Merit: 6793
Just writing some code
Add -daemon to the crontab command or add daemon=1 to your bitcoin.conf file.
hero member
Activity: 544
Merit: 507
Hi all, here I am again with my problems about nodes  Roll Eyes

This time is about another node I am setting on a pine64.

I tried to install a Bitcore node to create my own wallet service but that wasnt possible. If anyone had done this please write me to help me.

..following with the pine64 setting: I installed Bitcoin Core 0.15.0.1 and after executing bitcoind -daemon I can send RPC calls and the node answer every command.

Then I edited crontab so if the node gets rebooted bitcoind should start again.

This is when my problem occur, if I reboot the node bitcoind is executed but when I send RPC call I got this message:

Code:
pine@pine64:~$ bitcoin-cli getconnectioncount
error: couldn't connect to server: unknown (code -1)
(make sure server is running and you are connecting to the correct RPC port)

Here is my crontab config
Code:
pine@pine64:~$ crontab -e

# m h  dom mon dow   command

@reboot /usr/local/bin/bitcoind &

My bitcoin.conf file

Code:
pine@pine64:~$ cat .bitcoin/bitcoin.conf
##
## bitcoin.conf configuration file. Lines beginning with # are comments.
##

# Network-related settings:

# Run on the test network instead of the real bitcoin network.
#testnet=0

# Run a regression test network
#regtest=0

# Connect via a SOCKS5 proxy
#proxy=127.0.0.1:9050

# Bind to given address and always listen on it. Use [host]:port notation for IPv6
#bind=

# Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6
#whitebind=

##############################################################
##            Quick Primer on addnode vs connect            ##
##  Let's say for instance you use addnode=4.2.2.4          ##
##  addnode will connect you to and tell you about the      ##
##    nodes connected to 4.2.2.4.  In addition it will tell ##
##    the other nodes connected to it that you exist so     ##
##    they can connect to you.                              ##
##  connect will not do the above when you 'connect' to it. ##
##    It will *only* connect you to 4.2.2.4 and no one else.##
##                                                          ##
##  So if you're behind a firewall, or have other problems  ##
##  finding nodes, add some using 'addnode'.                ##
##                                                          ##
##  If you want to stay private, use 'connect' to only      ##
##  connect to "trusted" nodes.                             ##
##                                                          ##
##  If you run multiple nodes on a LAN, there's no need for ##
##  all of them to open lots of connections.  Instead       ##
##  'connect' them all to one node that is port forwarded   ##
##  and has lots of connections.                            ##
##       Thanks goes to [Noodle] on Freenode.               ##
##############################################################

# Use as many addnode= settings as you like to connect to specific peers
#addnode=69.164.218.197
#addnode=10.0.0.2:8333

# Alternatively use as many connect= settings as you like to connect ONLY to specific peers
#connect=69.164.218.197
#connect=10.0.0.1:8333

# Listening mode, enabled by default except when 'connect' is being used
#listen=1

# Maximum number of inbound+outbound connections.
#maxconnections=

#
# JSON-RPC options (for controlling a running Bitcoin/bitcoind process)
#

# server=1 tells Bitcoin-Qt and bitcoind to accept JSON-RPC commands
#server=0

# Bind to given address to listen for JSON-RPC connections. Use [host]:port notation for IPv6.
# This option can be specified multiple times (default: bind to all interfaces)
#rpcbind=

# If no rpcpassword is set, rpc cookie auth is sought. The default `-rpccookiefile` name
# is .cookie and found in the `-datadir` being used for bitcoind. This option is typically used
# when the server and client are run as the same user.
#
# If not, you must set rpcuser and rpcpassword to secure the JSON-RPC api. The first
# method(DEPRECATED) is to set this pair for the server and client:
#rpcuser=Ulysseys
#rpcpassword=YourSuperGreatPasswordNumber_DO_NOT_USE_THIS_OR_YOU_WILL_GET_ROBBED_385593
#
# The second method `rpcauth` can be added to server startup argument. It is set at initialization time
# using the output from the script in share/rpcuser/rpcuser.py after providing a username:
#
# ./share/rpcuser/rpcuser.py alice
# String to be appended to bitcoin.conf:
# rpcauth=alice:f7efda5c189b999524f151318c0c86$d5b51b3beffbc02b724e5d095828e0bc8b2456e9ac8757ae3211a5d9b16a22ae
# Your password:
# DONT_USE_THIS_YOU_WILL_GET_ROBBED_8ak1gI25KFTvjovL3gAM967mies3E=
#
# On client-side, you add the normal user/password pair to send commands:
#rpcuser=alice
#rpcpassword=DONT_USE_THIS_YOU_WILL_GET_ROBBED_8ak1gI25KFTvjovL3gAM967mies3E=
#
# You can even add multiple entries of these to the server conf file, and client can use any of them:
# rpcauth=bob:b2dd077cb54591a2f3139e69a897ac$4e71f08d48b4347cf8eff3815c0e25ae2e9a4340474079f55705f40574f4ec99

# How many seconds bitcoin will wait for a complete RPC HTTP request.
# after the HTTP connection is established.
#rpcclienttimeout=30

# By default, only RPC connections from localhost are allowed.
# Specify as many rpcallowip= settings as you like to allow connections from other hosts,
# either as a single IPv4/IPv6 or with a subnet specification.

# NOTE: opening up the RPC port to hosts outside your local trusted network is NOT RECOMMENDED,
# because the rpcpassword is transmitted over the network unencrypted.

# server=1 tells Bitcoin-Qt to accept JSON-RPC commands.
# it is also read by bitcoind to determine if RPC should be enabled
#rpcallowip=10.1.1.34/255.255.255.0
#rpcallowip=1.2.3.4/24
#rpcallowip=2001:db8:85a3:0:0:8a2e:370:7334/96

# Listen for RPC connections on this TCP port:
#rpcport=8332

# You can use Bitcoin or bitcoind to send commands to Bitcoin/bitcoind
# running on another host using this option:
#rpcconnect=127.0.0.1

# Create transactions that have enough fees so they are likely to begin confirmation within n blocks (default: 6).
# This setting is over-ridden by the -paytxfee option.
#txconfirmtarget=n

# Miscellaneous options

# Pre-generate this many public/private key pairs, so wallet backups will be valid for
# both prior transactions and several dozen future transactions.
#keypool=100

# Pay an optional transaction fee every time you send bitcoins.  Transactions with fees
# are more likely than free transactions to be included in generated blocks, so may
# be validated sooner.
#paytxfee=0.00

# Enable pruning to reduce storage requirements by deleting old blocks.
# This mode is incompatible with -txindex and -rescan.
# 0 = default (no pruning).
# 1 = allows manual pruning via RPC.
# >=550 = target to stay under in MiB.
prune=1000

# User interface options

# Start Bitcoin minimized
#min=1

# Minimize to the system tray
#minimizetotray=1

ps results when bitcoin -daemon is executed from cli

Code:
pine@pine64:~$ ps aux | grep bitcoind
pine      2214  9.9 22.6 1862152 461952 ?      Ssl  Oct31  95:02 bitcoind -daemon
pine     26429  0.0  0.0 121620   908 pts/0    S+   11:53   0:00 grep --color=auto bitcoind

ps results when bitcoin is executed after reboot in crontab

Code:
pine@pine64:~$ ps aux | grep bitcoind
pine       636 65.8 11.3 841216 230304 ?       DLl  11:56   0:11 /usr/local/bin/bitcoind
pine      1073  0.0  0.0 121620   904 pts/0    S+   11:57   0:00 grep --color=auto bitcoind
What am I missing in crontab?

I hope someone can tell me what is happening, I wont like to define a RPC user and password. For me it is ok to leave that blank and generate a new cookie everytime I start bitcoind.

Thanks guys
Jump to: