Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specific envvar system #16868

Closed
wants to merge 1 commit into from
Closed

Add specific envvar system #16868

wants to merge 1 commit into from

Conversation

cvengler
Copy link
Contributor

@cvengler cvengler commented Sep 13, 2019

See #16829

Description

This PR adds a way to set some CLI args with an environment variable.
The syntax for the envvars are BITCOIN_<ARGNAME>=<VALUE>
E.g BITCOIN_DATADIR=/home/emil/bitcoin/
Console arguments override setted envvars.
The envvars are always uppercase.

Testing

Set some envvars
On Unix:

export BITCOIN_DATADIR=/path/to/your/datadir
export BITCOIN_CONF=/path/to/your/conf
./bitcoin-qt

This will start Bitcoin-Qt using the datadir path with an english overlay.

List of supported envvars

  • datadir
  • conf
  • blocksdir
  • debuclogfile
  • includeconf
  • loadblock
  • pid
  • Others can be added by changing one line of code

@cvengler
Copy link
Contributor Author

The travis exception is there because all characters there are valid English Latin ASCII chars so there won't be any problems.

@cvengler cvengler mentioned this pull request Sep 14, 2019
@cvengler
Copy link
Contributor Author

Ping @ryanofsky

@ryanofsky
Copy link
Contributor

Two issues I see and suggested fixes I'd make:

  1. No documentation. Environment variables interpreted by bitcoin should be part of man pages and probably -help output. Suggested fix: explicitly list environment variables that affect bitcoin settings in relevant documentation, and say what the precedence is (seems to be less than command line settings and more than static config settings, which I think is a good choice).

  2. Too many environment variables are read. I think the only environment variables that should be read are BITCOIN_DATADIR are BITCOIN_CONF, because these are sufficient to bring in full configurations, and because exposing more variables creates chances for confusion and inconsistency (why is BITCOIN_BLOCKSDIR interpreted but BITCOIN_WALLETDIR ignored?), bikeshedding, future incompatibility across bitcoin versions, and silently ignored configuration errors. Suggested fix: stop interpreting other variables besides BITCOIN_DATADIR and BITCOIN_CONF.

Probably if this is going to be merged there should also be a python test covering this functionality. But you might could wait for more concept acks before putting work into that.

I guess I don't feel strongly, but overall I'd be for this change with rough edges removed.

@cvengler
Copy link
Contributor Author

@ryanofsky

  1. Sure, I will write the documentation later.
  2. I added all variables which take a file as an argument. Sure I will remove the others because they are unnecessary variables. However I still think that interpreting pid is ok because it is often used as an argument by init systems.

@cvengler
Copy link
Contributor Author

@ryanofsky Done

@maflcko
Copy link
Member

maflcko commented Sep 18, 2019

what the precedence is (seems to be less than command line settings and more than static config settings, which I think is a good choice).

This will break the functional (and possibly unit tests?)

@cvengler
Copy link
Contributor Author

@MarcoFalke How?
Config files or cmd args have a higher priority than envvars.
See travis, no errors

@maflcko
Copy link
Member

maflcko commented Sep 18, 2019

Config files or cmd args have a higher priority than envvars.

Would be nice to document this

See travis, no errors

No environment variables are set on travis, so it can't possibly fail

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 18, 2019

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #16659 (refactoring: Remove unused includes by practicalswift)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@cvengler
Copy link
Contributor Author

Added help

@laanwj
Copy link
Member

laanwj commented Sep 25, 2019

Concept ACK on BITCOIN_DATADIR an BITCOIN_CONF. I do not believe any of the others are necessary.

@cvengler
Copy link
Contributor Author

Ok, then I will remove BITCOIN_PID

@cvengler
Copy link
Contributor Author

Done 6ccb229

@fanquake
Copy link
Member

@emilengler Can you squash your chanegs into a single commit (dropping all intermediate commit messages etc), add a more descriptive commit message and body as well as update the PR text to reflect the current state of this PR.

@cvengler
Copy link
Contributor Author

I removed the help from the -help command to the docs because this was only causing a cricular dependency

@cvengler
Copy link
Contributor Author

@fanquake Done

Name | Option equivalent
-- | --
BITCOIN_DATADIR | -datadir
BITCOIN_CONF | -conf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This complicates the init process and argument parsing. I am ~0 on the overall pull, but at the very least, this should include documentation on the precedence. Tests wouldn't hurt either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't really complicates the init process. It just checks if a specific argument is set. If not it will use the envvar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoFalke Updated, please check

This commit adds a way to set the -conf and -datadir flag using the environment variables BITCOIN_CONF and BITCOIN_DATADIR
@cvengler
Copy link
Contributor Author

Closed because of lack of interest

@cvengler cvengler closed this Oct 14, 2019
@cvengler cvengler deleted the 2019-09-specific-envvar branch October 14, 2019 15:27
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants