Solved How to start the bitcoind service at boot with a .conf file?

Hello everyone,

I have installed a full bitcoind node and configured the config file.

When I run the command
bitcoind -conf=/usr/local/etc/bitcoin.conf
everything works fine.

Here is what I added to the /etc/rc.conf file but the service does not start on startup.

Code:
bitcoind_enable="YES"
bitcoind_user="bitcoin"
bitcoind_group="bitcoin"
bitcoind_data="/var/db/bitcoind"
bitcoind_configfile="/usr/local/etc/bitcoin.conf"

What did I miss?
thank you,
good to you.
 
Read the /usr/local/etc/rc.d/bitcoind script to see how you can configure it. If that script doesn't exist it's not going to "magically" start the service by adding a few variables to rc.conf. Services require rc(8) scripts to make this work.
 
Hello everyone,

I have installed a full bitcoind node and configured the config file.

When I run the command
bitcoind -conf=/usr/local/etc/bitcoin.conf
everything works fine.

Here is what I added to the /etc/rc.conf file but the service does not start on startup.

Code:
bitcoind_enable="YES"
bitcoind_user="bitcoin"
bitcoind_group="bitcoin"
bitcoind_data="/var/db/bitcoind"
bitcoind_configfile="/usr/local/etc/bitcoin.conf"

What did I miss?
thank you,
good to you.
Read the /usr/local/etc/rc.d/bitcoind script to see how you can configure it. If that script doesn't exist it's not going to "magically" start the service by adding a few variables to rc.conf. Services require rc(8) scripts to make this work.
Thank you for your reply.
The bitcoind script does exist in /usr/local/etc/rc.d/ so we can exclude magic.
I'm trying to understand the bitcoind script but I'm not a developer.

From what I can understand from reading the bitcoind script, you would normally add the following lines in /etc/rc.conf:
Code:
bitcoind_enable="YES"
bitcoind_conf="/usr/local/etc/bitcoin.conf"
This is what I did but it still doesn't work on startup.
 
Which port/package did you install? So I can have a look at the actual script too.

Does it start if you run service bitcoind start? Any errors showing if it doesn't start? Log files?
 
Which port/package did you install? So I can have a look at the actual script too.

Does it start if you run service bitcoind start? Any errors showing if it doesn't start? Log files?
Thank you,

I forgot to specify my version of FreeBSD
Code:
uname -v
FreeBSD 12.2-RELEASE r366954 GENERIC

The version of the bitcoind package is:
Code:
pkg info | grep bitcoin
bitcoin-daemon-0.20.1_3        Virtual Peer-to-Peer Currency (Daemon)
bitcoin-utils-0.20.1_1         Virtual Peer-to-Peer Currency (CLI and Utilities)

Here is what I did:

1) I execute the command manually then I check
Code:
bitcoind -conf=/usr/local/etc/bitcoin.conf
Bitcoin Core starting
ps aux | grep bitcoind
root         1386   6.2 12.5 2146116 615480  -  Ds   12:57     0:16.20 bitcoind -conf=/usr/local

2) I check by the command service which tells me that the service is not working while it is working
Code:
service bitcoind status
Bitcoind is not running
service bitcoind stop  
Stopping bitcoind:
Bitcoind is not running

3) I kill the bitcoind service to be sure that it works fine
Code:
ps aux | grep bitcoind
root         1386   6.2 12.5 2146116 615480  -  Ds   12:57     0:16.20 bitcoind -conf=/usr/local
kill -9 1386
root@panoramix /home/aiko]# ps aux | grep bitcoind
root         1415   0.0  0.1  11164   2532  1  R+   13:00     0:00.00 grep bitcoind

4) I try to start the service by following your advice then I check that it is working
Code:
service bitcoind start
Performing sanity check on bitcoind configuration:
Bitcoind is not running
Starting bitcoind:
service bitcoind status
Bitcoind is not running
ps aux | grep bitcoind
root         1437   0.0  0.1  11160   2528  1  R+   13:02     0:00.00 grep bitcoind
cat /var/log/messages | grep bitcoin
nothing

When I go through the bitcoind -conf=/usr/local/etc/bitcoin.conf command it works but I can't get it to work on startup.
When I go through the service bitcoind start command, it does not start and I have no error in the logs.
 
When you started it by hand you're running it as root. Any log files or temporary files it creates will also be owned by root. When you start the service it runs on the bitcoind user account. That account can't open or write to those temporary files anymore because they're root owned. I see that the rc(8) script actually takes this into account and corrects the ownership of the files in /var/db/bitcoin, so this shouldn't be a problem. But check the ownership and permissions of /var/db/bitcoin just to make sure.

I haven't looked at the documentation of bitcoind itself but does the configuration allow you to bind it to a specific IP and/or port? Make sure this is a port above 1024. Only root can open ports below 1024.

Tip: don't needlessly use kill -9 .... This forcefully removes a process from the process tables and dumps a core(5). Use a 'regular' kill ...., this will send a SIGTERM to the process allowing it to cleanly shutdown on its own. NEVER send a SIGKILL if it's not needed. Please understand the difference or you will inevitably suffer data loss because processes don't get a chance to cleanly stop.
 
Thanks, I will heed your advice regarding the kill command.

Here are the properties of /var/db/bitcoin
Code:
ls -lh /var/db/bitcoin
drwxr-xr-x 3 bitcoin bitcoin 512B Jan 27 13:01 bitcoin

Code:
ls -lh /var/db/bitcoin/
total 56
-rw-------  1 bitcoin  bitcoin     0B Dec  5 15:59 .lock
-rw-------  1 bitcoin  bitcoin    37B Dec  5 15:59 banlist.dat
drwx------  3 bitcoin  bitcoin   512B Dec  5 15:59 blocks
-rw-------  1 bitcoin  bitcoin    45K Jan 27 13:01 debug.log

Here is the requested part for the bitcoin.conf file
Code:
#----BITCOIN CORE----
## Specify data directory
datadir=/nfs2/blockchain

#Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>)
blocksdir=/nfs2/blockchain

# ---- NETWORKING ----
# Bind to given address and always listen on it. Use [host]: port notation for IPv6
# bind = <addr>
bind = 192.168.1.13

# Listen for incoming connections on non-default port.
port = 8333
# Listen for connections on <port> (default: 8333, testnet: 18333, regtest: 18444)

I just noticed while discussing with you that in my bitcoin.conf file, I specify to make the files in /nfs2/blochain (which is a hard disk of the system that I added because the full node takes + - 349G .

If I check the properties /nfs2/blockchain gives this.
Code:
ls -lh /nfs2/
total 32804
-r--------  1 root  wheel    32M Jun  2  2018 .sujournal
drwxr-xr-x  4 root  wheel   512B Jan 27 14:42 blockchain

Code:
ls -lh /nfs2/blockchain/
total 115620
-rw-------  1 root  wheel    75B Jan 27 13:23 .cookie
-rw-------  1 root  wheel     0B Jan  8 08:20 .lock
-rw-------  1 root  wheel    37B Jan  8 08:20 banlist.dat
-rw-------  1 root  wheel     5B Jan 27 13:23 bitcoind.pid
drwx------  3 root  wheel   116K Jan 27 09:38 blocks
drwx------  2 root  wheel    46K Jan 27 14:17 chainstate
-rw-------  1 root  wheel   9.9M Jan 27 14:50 debug.log
-rw-------  1 root  wheel   242K Jan 27 11:43 fee_estimates.dat
-rw-------  1 root  wheel    98M Jan 27 11:43 mempool.dat
-rw-------  1 root  wheel   4.0M Jan 27 14:42 peers.dat

Shouldn't I chown -R bitcoin:bitcoin /nfs2/blockchain to allow bitcoind user and bitcoind group to have write access?

Because when starting the machine if I check the /etc/rc.conf file it does contain the properties this.
Code:
bitcoind_enable="YES"
bitcoind_user="bitcoin"
bitcoind_group="bitcoin"
bitcoind_conf="/usr/local/etc/bitcoin.conf"

So as the bitcoind daemon is run by the user and the bitcoin group and they do not have access to /nfs2/blockchain which only has access for the user root and the wheel group, this one does not launch not.

I think I made a stupid mistake.
 
Set bitcoind_data in rc.conf to /nfs2/blockchain and don't set it in bitcoind.conf (or at least make sure they're set the same). The rc(8) script launches bitcoind(1) with the -datadir="${bitcoind_data_dir}" argument. Command line arguments typically overrule any configuration parameters. Setting bitcoind_data will also cause the rc(8) script to apply the correct permissions to the directory:

Code:
chown -R "${bitcoind_user}:${bitcoind_group}" "${bitcoind_data_dir}"

Code:
#Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>)
blocksdir=/nfs2/blockchain
Don't set it if you want it to be the same as datadir. The datadir is overruled by command line parameters (-datadir="${bitcoind_data_dir}")

So your current setup will use /var/db/bitcoind as datadir (due to bitcoind_data) and /nfs2/blockchain for blocksdir (because you set it explicitly in bitcoind.conf).
 
By following your advice, I am starting to have very good results.

I did this:
chown -R bitcoin: bitcoin /nfs2/blockchain

Is this the same as the command you gave me chown -R "$ {bitcoind_user}: $ {bitcoind_group}" "$ {bitcoind_data_dir}"?

I added this to rc.conf:
Code:
bitcoind_enable="YES"
bitcoind_user="bitcoin"
bitcoind_group="bitcoin"
bitcoind_conf="/usr/local/etc/bitcoin.conf"
bitcoind_data_dir="/nfs2/blockchain"

I did not touch the /usr/local/etc/bitcoin.conf file

I restarted the system and checked:
Code:
ps aux | grep bitcoin
bitcoin      1123   6.6 11.2 2124408 554408  -  Ss   16:01    0:38.58 /usr/local/bin/bitcoind -conf=/usr/local/etc/bitcoin.conf -datadir=/nfs2/blockchain

Now the process starts when the machine starts up with the "bitcoin" user and no longer with the "root" user.
 
I did this:
chown -R bitcoin: bitcoin /nfs2/blockchain

Is this the same as the command you gave me chown -R "$ {bitcoind_user}: $ {bitcoind_group}" "$ {bitcoind_data_dir}"?
You don't need to do this. The rc(8) script does that for you, as long as bitcoind_data_dir is pointing to the right directory.

I did not touch the /usr/local/etc/bitcoin.conf file
Do remove (or remark) the datadir and blocksdir options in bitcoin.conf. That will avoid any confusion in the future if you decide to change the bitcoind_data_dir setting in rc.conf.
 
I will comment out the blockdir and datadir parameters in the /usr/local/etc/bitcoin.conf file
Thank you for all your good advice, your relevant answers and the quality of your support.
We can say that this subject is resolved.
Can you put it to satus solved please as I don't think I have permission to do so.
Thanks again.
Cordially.
👍
 
Back
Top