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.

198 lines
5.0 KiB

  1. package command
  2. import (
  3. "io/ioutil"
  4. "path/filepath"
  5. )
  6. func init() {
  7. cmdScaffold.Run = runScaffold // break init cycle
  8. }
  9. var cmdScaffold = &Command{
  10. UsageLine: "scaffold [filer]",
  11. Short: "generate basic configuration files",
  12. Long: `Generate filer.toml with all possible configurations for you to customize.
  13. `,
  14. }
  15. var (
  16. outputPath = cmdScaffold.Flag.String("output", "", "if not empty, save the configuration file to this directory")
  17. config = cmdScaffold.Flag.String("config", "filer", "[filer|replication] the configuration file to generate")
  18. )
  19. func runScaffold(cmd *Command, args []string) bool {
  20. content := ""
  21. switch *config {
  22. case "filer":
  23. content = FILER_TOML_EXAMPLE
  24. case "replication":
  25. content = REPLICATION_TOML_EXAMPLE
  26. }
  27. if content == "" {
  28. println("need a valid -config option")
  29. return false
  30. }
  31. if *outputPath != "" {
  32. ioutil.WriteFile(filepath.Join(*outputPath, *config+".toml"), []byte(content), 0x755)
  33. } else {
  34. println(content)
  35. }
  36. return true
  37. }
  38. const (
  39. FILER_TOML_EXAMPLE = `
  40. # A sample TOML config file for SeaweedFS filer store
  41. # Used with "weed filer" or "weed server -filer"
  42. # Put this file to one of the location, with descending priority
  43. # ./filer.toml
  44. # $HOME/.seaweedfs/filer.toml
  45. # /etc/seaweedfs/filer.toml
  46. [memory]
  47. # local in memory, mostly for testing purpose
  48. enabled = false
  49. [leveldb]
  50. # local on disk, mostly for simple single-machine setup, fairly scalable
  51. enabled = true
  52. dir = "." # directory to store level db files
  53. ####################################################
  54. # multiple filers on shared storage, fairly scalable
  55. ####################################################
  56. [mysql]
  57. # CREATE TABLE IF NOT EXISTS filemeta (
  58. # dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
  59. # name VARCHAR(1000) COMMENT 'directory or file name',
  60. # directory VARCHAR(4096) COMMENT 'full path to parent directory',
  61. # meta BLOB,
  62. # PRIMARY KEY (dirhash, name)
  63. # ) DEFAULT CHARSET=utf8;
  64. enabled = false
  65. hostname = "localhost"
  66. port = 3306
  67. username = "root"
  68. password = ""
  69. database = "" # create or use an existing database
  70. connection_max_idle = 2
  71. connection_max_open = 100
  72. [postgres]
  73. # CREATE TABLE IF NOT EXISTS filemeta (
  74. # dirhash BIGINT,
  75. # name VARCHAR(1000),
  76. # directory VARCHAR(4096),
  77. # meta bytea,
  78. # PRIMARY KEY (dirhash, name)
  79. # );
  80. enabled = false
  81. hostname = "localhost"
  82. port = 5432
  83. username = "postgres"
  84. password = ""
  85. database = "" # create or use an existing database
  86. sslmode = "disable"
  87. connection_max_idle = 100
  88. connection_max_open = 100
  89. [cassandra]
  90. # CREATE TABLE filemeta (
  91. # directory varchar,
  92. # name varchar,
  93. # meta blob,
  94. # PRIMARY KEY (directory, name)
  95. # ) WITH CLUSTERING ORDER BY (name ASC);
  96. enabled = false
  97. keyspace="seaweedfs"
  98. hosts=[
  99. "localhost:9042",
  100. ]
  101. [redis]
  102. enabled = false
  103. address = "localhost:6379"
  104. password = ""
  105. db = 0
  106. [redis_cluster]
  107. enabled = false
  108. addresses = [
  109. "localhost:30001",
  110. "localhost:30002",
  111. "localhost:30003",
  112. "localhost:30004",
  113. "localhost:30005",
  114. "localhost:30006",
  115. ]
  116. ####################################################
  117. # notification
  118. # sends filer updates for each file to an external message queue
  119. ####################################################
  120. [notification.log]
  121. enabled = false
  122. [notification.kafka]
  123. enabled = false
  124. hosts = [
  125. "localhost:9092"
  126. ]
  127. topic = "seaweedfs_filer"
  128. `
  129. REPLICATION_TOML_EXAMPLE = `
  130. # A sample TOML config file for replicating SeaweedFS filer
  131. # Used with "weed filer.replicate"
  132. # Put this file to one of the location, with descending priority
  133. # ./replication.toml
  134. # $HOME/.seaweedfs/replication.toml
  135. # /etc/seaweedfs/replication.toml
  136. [source.filer]
  137. enabled = true
  138. grpcAddress = "localhost:18888"
  139. directory = "/buckets" # all files under this directory tree are replicated
  140. [notification.kafka]
  141. enabled = false
  142. hosts = [
  143. "localhost:9092"
  144. ]
  145. topic = "seaweedfs_filer1_to_filer2"
  146. offsetFile = "./last.offset"
  147. offsetSaveIntervalSeconds = 10
  148. [sink.filer]
  149. enabled = false
  150. grpcAddress = "localhost:18888"
  151. directory = "/backup" # all replicated files are under this directory tree
  152. replication = ""
  153. collection = ""
  154. ttlSec = 0
  155. [sink.s3]
  156. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  157. # default loads credentials from the shared credentials file (~/.aws/credentials).
  158. enabled = false
  159. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  160. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  161. region = "us-east-2"
  162. bucket = "your_bucket_name" # an existing bucket
  163. directory = "" # destination directory (do not prefix or suffix with "/")
  164. [sink.google_cloud_storage]
  165. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  166. enabled = false
  167. google_application_credentials = "/path/to/x.json" # path to json credential file
  168. bucket = "your_bucket_seaweedfs" # an existing bucket
  169. directory = "/" # destination directory
  170. `
  171. )