Config CLI option, datadir correctly read from config (#1807)

* Config CLI option, datadir correctly read from config

* Change --config to --conf, add docs
This commit is contained in:
Ben Carman 2020-08-13 10:53:25 -05:00 committed by GitHub
parent 099c33ff02
commit 701afe348a
2 changed files with 44 additions and 7 deletions

View file

@ -5,6 +5,7 @@ import java.nio.file.{Path, Paths}
import akka.actor.ActorSystem
import akka.dispatch.Dispatchers
import akka.http.scaladsl.Http
import com.typesafe.config.ConfigFactory
import org.bitcoins.chain.api.ChainApi
import org.bitcoins.chain.blockchain.ChainHandler
import org.bitcoins.chain.config.ChainAppConfig
@ -16,7 +17,7 @@ import org.bitcoins.chain.models.{
import org.bitcoins.core.Core
import org.bitcoins.core.config.{BitcoinNetworks, MainNet, RegTest, TestNet3}
import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil, NetworkUtil}
import org.bitcoins.db.AppConfig
import org.bitcoins.db._
import org.bitcoins.feeprovider.BitcoinerLiveFeeRateProvider
import org.bitcoins.node._
import org.bitcoins.node.config.NodeAppConfig
@ -25,6 +26,7 @@ import org.bitcoins.wallet.Wallet
import org.bitcoins.wallet.config.WalletAppConfig
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.util.Properties
object Main extends App with BitcoinSLogger {
@ -34,14 +36,33 @@ object Main extends App with BitcoinSLogger {
val dataDirIndexOpt = {
argsWithIndex.find(_._1.toLowerCase == "--datadir")
}
val datadirPath = dataDirIndexOpt match {
case None => AppConfig.DEFAULT_BITCOIN_S_DATADIR
val datadirPathOpt = dataDirIndexOpt match {
case None => None
case Some((_, dataDirIndex)) =>
val str = args(dataDirIndex + 1)
Paths.get(str)
val usableStr = str.replace("~", Properties.userHome)
Some(Paths.get(usableStr))
}
val baseConfig = AppConfig.getBaseConfig(datadirPath)
val configIndexOpt = {
argsWithIndex.find(_._1.toLowerCase == "--conf")
}
val baseConfig = configIndexOpt match {
case None =>
val configPath =
datadirPathOpt.getOrElse(AppConfig.DEFAULT_BITCOIN_S_DATADIR)
AppConfig.getBaseConfig(configPath)
case Some((_, configIndex)) =>
val str = args(configIndex + 1)
val usableStr = str.replace("~", Properties.userHome)
val path = Paths.get(usableStr)
ConfigFactory.parseFile(path.toFile).resolve()
}
val configDataDir = Paths.get(
baseConfig.getStringOrElse("bitcoin-s.datadir",
AppConfig.DEFAULT_BITCOIN_S_DATADIR.toString))
val datadirPath = datadirPathOpt.getOrElse(configDataDir)
val networkStr = baseConfig.getString("bitcoin-s.network")
val network = BitcoinNetworks.fromString(networkStr)
@ -64,7 +85,15 @@ object Main extends App with BitcoinSLogger {
system.log.info("Akka logger started")
implicit val conf: BitcoinSAppConfig = {
BitcoinSAppConfig(datadirPath)
val dataDirOverrideOpt = datadirPathOpt.map(dir =>
ConfigFactory.parseString(s"bitcoin-s.datadir = $dir"))
dataDirOverrideOpt match {
case Some(dataDirOverride) =>
BitcoinSAppConfig(datadirPath, baseConfig, dataDirOverride)
case None =>
BitcoinSAppConfig(datadirPath, baseConfig)
}
}
val rpcPortOpt: Option[Int] = {

View file

@ -19,7 +19,7 @@ The server project provides a away to access information from these three projec
You can build the server with the [sbt native packager](https://github.com/sbt/sbt-native-packager).
The native packager offers [numerous ways to package the project](https://github.com/sbt/sbt-native-packager#examples).
In this example we are going to use `stage` which will produce bash scripts we can easily execute. You can stage the server with the following command
In this example we are going to use `stage` which will produce bash scripts we can easily execute. You can stage the server with the following command.
```bash
$ sbt appServer/universal:stage
@ -31,12 +31,20 @@ This will produce a script to execute bitcoin-s which you can start with
$ ./app/server/target/universal/stage/bin/bitcoin-s-server
```
### Configuration
If you would like to pass in a custom datadir for your server, you can do
```bash
./app/server/target/universal/stage/bin/bitcoin-s-server --datadir /path/to/datadir/
```
To use a config file that is not the `bitcoin-s.conf` file in your datadir, you can do
```bash
./app/server/target/universal/stage/bin/bitcoin-s-server --conf /path/to/file.conf
```
You can also pass in a custom `rpcport` to bind to
```bash