diff options
| author | chrislu <chris.lu@gmail.com> | 2022-03-19 00:22:47 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-03-19 00:22:47 -0700 |
| commit | 3da2b83b38e5e9ac3f41092afdd3cf2bf2845285 (patch) | |
| tree | b70c207d6ed4191cfd1db4b07beb1a086f35678d | |
| parent | 2824940ecf62073e00a4d7e2a069b693082b31cf (diff) | |
| download | seaweedfs-3da2b83b38e5e9ac3f41092afdd3cf2bf2845285.tar.xz seaweedfs-3da2b83b38e5e9ac3f41092afdd3cf2bf2845285.zip | |
Added a "-conf_dir" option to customize *.toml configuration file directory.
fix https://github.com/chrislusf/seaweedfs/issues/2753
| -rw-r--r-- | weed/util/config.go | 25 | ||||
| -rw-r--r-- | weed/weed.go | 3 |
2 files changed, 23 insertions, 5 deletions
diff --git a/weed/util/config.go b/weed/util/config.go index ae9397340..f09ac7e5e 100644 --- a/weed/util/config.go +++ b/weed/util/config.go @@ -9,6 +9,20 @@ import ( "github.com/chrislusf/seaweedfs/weed/glog" ) +var ( + ConfigurationFileDirectory DirectoryValueType +) + +type DirectoryValueType string + +func (s *DirectoryValueType) Set(value string) error { + *s = DirectoryValueType(value) + return nil +} +func (s *DirectoryValueType) String() string { + return string(*s) +} + type Configuration interface { GetString(key string) string GetBool(key string) bool @@ -20,11 +34,12 @@ type Configuration interface { func LoadConfiguration(configFileName string, required bool) (loaded bool) { // find a filer store - viper.SetConfigName(configFileName) // name of config file (without extension) - viper.AddConfigPath(".") // optionally look for config in the working directory - viper.AddConfigPath("$HOME/.seaweedfs") // call multiple times to add many search paths - viper.AddConfigPath("/usr/local/etc/seaweedfs/") // search path for bsd-style config directory in - viper.AddConfigPath("/etc/seaweedfs/") // path to look for the config file in + viper.SetConfigName(configFileName) // name of config file (without extension) + viper.AddConfigPath(ResolvePath(ConfigurationFileDirectory.String())) // path to look for the config file in + viper.AddConfigPath(".") // optionally look for config in the working directory + viper.AddConfigPath("$HOME/.seaweedfs") // call multiple times to add many search paths + viper.AddConfigPath("/usr/local/etc/seaweedfs/") // search path for bsd-style config directory in + viper.AddConfigPath("/etc/seaweedfs/") // path to look for the config file in if err := viper.MergeInConfig(); err != nil { // Handle errors reading the config file if strings.Contains(err.Error(), "Not Found") { diff --git a/weed/weed.go b/weed/weed.go index 068d2077c..19723e0e6 100644 --- a/weed/weed.go +++ b/weed/weed.go @@ -4,6 +4,7 @@ import ( "embed" "fmt" weed_server "github.com/chrislusf/seaweedfs/weed/server" + "github.com/chrislusf/seaweedfs/weed/util" flag "github.com/chrislusf/seaweedfs/weed/util/fla9" "io" "io/fs" @@ -40,6 +41,8 @@ var static embed.FS func init() { weed_server.StaticFS, _ = fs.Sub(static, "static") + + flag.Var(&util.ConfigurationFileDirectory, "conf_dir", "directory with toml configuration files") } func main() { |
