electrs icon indicating copy to clipboard operation
electrs copied to clipboard

Config: the default configuration file is ignored, and so is `--conf`

Open ildella opened this issue 1 year ago • 11 comments

Have you read the documentation? Yes.

How did you configure electrs?

Is running on a raspberrypi with latest Raspian OS. I built it from scratch.

$ cat ~/.electrs/config.toml
[server]
electrum_rpc_addr = "127.0.0.1:50001"

[bitcoin]
network = "bitcoin"
daemon_dir = "/home/pi/zio/bitcoin"
cookie_file = "/home/pi/zio/bitcoin/.cookie"
db_dir = "/home/pi/zio/electrs/db"
log_filters = "TRACE"

Environment variables: none set Arguments: none set

Debug output of configuration

$ ./target/release/electrs
Starting electrs 0.10.5 on aarch64 linux with Config { network: Bitcoin, db_path: "./db/bitcoin", db_log_dir: None, daemon_dir: "/home/pi/.bitcoin", daemon_auth: CookieFile("/home/pi/.bitcoin/.cookie"), daemon_rpc_addr: 127.0.0.1:8332, daemon_p2p_addr: 127.0.0.1:8333, electrum_rpc_addr: 127.0.0.1:50001, monitoring_addr: 127.0.0.1:4224, wait_duration: 10s, jsonrpc_timeout: 15s, index_batch_size: 10, index_lookup_limit: None, reindex_last_blocks: 0, auto_reindex: true, ignore_mempool: false, sync_once: false, skip_block_download_wait: false, disable_electrum_rpc: false, server_banner: "Welcome to electrs 0.10.5 (Electrum Rust Server)!", signet_magic: f9beb4d9, args: [] }
Error: electrs failed

Caused by:
    0: failed to open bitcoind cookie file: /home/pi/.bitcoin/.cookie
    1: No such file or directory (os error 2)

Expected behavior I would expect the configuration to be loaded, as expected from the docs: https://github.com/romanz/electrs/blob/master/doc/config.md#configuration-files-and-priorities

Actual behavior It is clear that electrs is starting using default configuration, looking for files in /home/pi/.bitcoin/ while my config states otherwise.

ildella avatar Jul 29 '24 13:07 ildella

Firstly, are you sure you're using a recent version from this repository? Not forks made by other people as those tend to introduce incompatible changes. Also are you sure you're using a recent version? Are you sure you're launching it with correct HOME environment variable? Are you sure you're not using some kind of isolation like a container or funny systemd options?

Sorry if these seem like stupid questions but the code definitely worked last time I tested and also there weren't any changes. And the code looks correct to me so OS issues are more likely.

Kixunil avatar Jul 29 '24 14:07 Kixunil

I am more than positive that something is wrong with what I do and not with the code. Still I did follow instructions to the letter.

  1. yes, git repo is this one.
  2. I did clone and build few days ago. A git pull just got me a few updates, I'll try again but it's very unlikely that is the problem.
  3. what is the correct HOME env var and why there is a correct one? As you see I run electrs without any additional params.
  4. I am not using any isolation container or other systemd option. I am starting it from the terminal with the command I pasted up there.

ildella avatar Jul 29 '24 14:07 ildella

And to be clear, if I put the config in the command line like

/home/pi/apps/electrs/target/release/electrs --log-filters INFO --db-dir /home/pi/zio/electrs/db --electrum-rpc-addr="127.0.0.1:50001" --daemon-dir=/home/pi/zio/bitcoin

They are used and it starts. Is just that it does not load from the toml config.

ildella avatar Jul 29 '24 14:07 ildella

3. what is the correct HOME env var and why there is a correct one? As you see I run electrs without any additional params.

It's normally set by the OS (see echo $HOME) but it gets messed up occasionally. It looks like it should be /home/pi in your case.

Kixunil avatar Jul 29 '24 15:07 Kixunil

I had a similar issue on a laptop, this solved it

https://github.com/romanz/electrs/issues/199#issuecomment-558022334

Maj3re avatar Aug 07 '24 02:08 Maj3re

I had a similar issue. Seems the binary can't start if you call --conf from a none "standard" (hard coded) directory. In my init script, i had to cd into the path of the config file, or else it would refuse to read the file.

thnkman avatar Sep 01 '24 12:09 thnkman

@thnkman what was the error message? Relative paths should work normally as any other.

Kixunil avatar Sep 01 '24 17:09 Kixunil

@thnkman what was the error message? Relative paths should work normally as any other.

IIRC It was along the lines of "No such file or directory"

thnkman avatar Sep 01 '24 17:09 thnkman

Then you must've supplied a wrong path. --conf never failed me and never required me to cd or do whatever else.

Kixunil avatar Sep 02 '24 07:09 Kixunil

Then you must've supplied a wrong path. --conf never failed me and never required me to cd or do whatever else.

I spent some time trying to troubleshoot this. Here are my findings:

In my initscript, i have the following; runuser -u "$USER" -- sh -c "$PRGNAM --conf $CONFDIR/config.toml >$LOGDIR/$PRGNAM.log 2>&1 & echo \$! >$PIDFILE"

When this line is executed, electrs will spit out a error: Error: Failed to read configuration file electrs.toml: Permission denied (os error 13)

If i rename config.toml to electrs.toml: Error: Failed to read configuration file /etc/electrs/electrs.toml: No such file or directory (os error 2)

Then, if i add --skip-default-conf-files to the runuser line in my initscript, every thing is fine.

This might be expected behavior, but it's a little counter intuitive, at least to me.

thnkman avatar Sep 03 '24 18:09 thnkman

It's expected but I think we could improve the error message somehow. Electrs tries to read configuration from default locations first and merge it together with other things. --skip-default-conf-files is the correct way to handle your use case.

Kixunil avatar Sep 03 '24 19:09 Kixunil