You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.1 KiB

  1. package filer2
  2. import (
  3. "os"
  4. "github.com/spf13/viper"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. )
  7. const (
  8. FILER_TOML_EXAMPLE = `
  9. # A sample TOML config file for SeaweedFS filer store
  10. # local in memory, mostly for testing purpose
  11. [memory]
  12. enabled = false
  13. [leveldb]
  14. enabled = false
  15. dir = "." # directory to store level db files
  16. [mysql]
  17. enabled = true
  18. server = "192.168.1.1"
  19. port = 8080
  20. username = ""
  21. password = ""
  22. database = ""
  23. connection_max_idle = 100
  24. connection_max_open = 100
  25. [postgres]
  26. enabled = false
  27. server = "192.168.1.1"
  28. port = 8080
  29. username = ""
  30. password = ""
  31. database = ""
  32. connection_max_idle = 100
  33. connection_max_open = 100
  34. `
  35. )
  36. var (
  37. Stores []FilerStore
  38. )
  39. func (f *Filer) LoadConfiguration() {
  40. // find a filer store
  41. viper.SetConfigName("filer") // name of config file (without extension)
  42. viper.AddConfigPath(".") // optionally look for config in the working directory
  43. viper.AddConfigPath("$HOME/.seaweedfs") // call multiple times to add many search paths
  44. viper.AddConfigPath("/etc/seaweedfs/") // path to look for the config file in
  45. if err := viper.ReadInConfig(); err != nil { // Handle errors reading the config file
  46. glog.Fatalf("Failed to load filer.toml file from current directory, or $HOME/.seaweedfs/, or /etc/seaweedfs/" +
  47. "\n\nPlease follow this example and add a filer.toml file to " +
  48. "current directory, or $HOME/.seaweedfs/, or /etc/seaweedfs/:\n" + FILER_TOML_EXAMPLE)
  49. }
  50. glog.V(0).Infof("Reading filer configuration from %s", viper.ConfigFileUsed())
  51. for _, store := range Stores {
  52. if viper.GetBool(store.GetName() + ".enabled") {
  53. viperSub := viper.Sub(store.GetName())
  54. if err := store.Initialize(viperSub); err != nil {
  55. glog.Fatalf("Failed to initialize store for %s: %+v",
  56. store.GetName(), err)
  57. }
  58. f.SetStore(store)
  59. glog.V(0).Infof("Configure filer for %s from %s", store.GetName(), viper.ConfigFileUsed())
  60. return
  61. }
  62. }
  63. println()
  64. println("Supported filer stores are:")
  65. for _, store := range Stores {
  66. println(" " + store.GetName())
  67. }
  68. println()
  69. println("Please configure a supported filer store in", viper.ConfigFileUsed())
  70. println()
  71. os.Exit(-1)
  72. }