From 851569f14e92507611b8a37a0e3824434ecf234d Mon Sep 17 00:00:00 2001 From: "Dan.. Noyes" Date: Wed, 13 Apr 2016 15:29:26 -0400 Subject: [PATCH] Updated config to allow the ability to change the home directory (#109) Can use -A or --appdata to change the directory for dcrd to store files. --- config.go | 14 ++++++++++++++ dcrd.go | 2 ++ 2 files changed, 16 insertions(+) diff --git a/config.go b/config.go index 4592ed2b..5547b2b4 100644 --- a/config.go +++ b/config.go @@ -68,6 +68,7 @@ var runServiceCommand func(string) error // // See loadConfig for details on the configuration load process. type config struct { + DcrdHomeDir string `short:"A" long:"appdata" description:"Path to dcrd home directory"` ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"` ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"` DataDir string `short:"b" long:"datadir" description:"Directory to store data"` @@ -313,6 +314,7 @@ func newConfigParser(cfg *config, so *serviceOptions, options flags.Options) *fl func loadConfig() (*config, []string, error) { // Default config. cfg := config{ + DcrdHomeDir: dcrdHomeDir, ConfigFile: defaultConfigFile, DebugLevel: defaultLogLevel, MaxPeers: defaultMaxPeers, @@ -371,6 +373,18 @@ func loadConfig() (*config, []string, error) { os.Exit(0) } + // Update the home directory for dcrd if specified. Since the home + // directory is updated, other variables need to be updated to + // reflect the new changes. + if len(preCfg.DcrdHomeDir) > 0 { + cfg.DcrdHomeDir, _ = filepath.Abs(preCfg.DcrdHomeDir) + cfg.ConfigFile = filepath.Join(cfg.DcrdHomeDir, defaultConfigFilename) + cfg.DataDir = filepath.Join(cfg.DcrdHomeDir, defaultDataDirname) + cfg.RPCKey = filepath.Join(cfg.DcrdHomeDir, "rpc.key") + cfg.RPCCert = filepath.Join(cfg.DcrdHomeDir, "rpc.cert") + cfg.LogDir = filepath.Join(cfg.DcrdHomeDir, defaultLogDirname) + } + // Load additional config from file. var configFileError error parser := newConfigParser(&cfg, &serviceOpts, flags.Default) diff --git a/dcrd.go b/dcrd.go index 0329a4d0..3e071fb2 100644 --- a/dcrd.go +++ b/dcrd.go @@ -44,6 +44,8 @@ func dcrdMain(serverChan chan<- *server) error { // Show version at startup. dcrdLog.Infof("Version %s", version()) + // Show dcrd home dir location + dcrdLog.Debugf("Dcrd home dir: %s", cfg.DcrdHomeDir) // Enable http profiling server if requested. if cfg.Profile != "" {