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.

243 lines
6.8 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  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|notification|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 "notification":
  25. content = NOTIFICATION_TOML_EXAMPLE
  26. case "replication":
  27. content = REPLICATION_TOML_EXAMPLE
  28. }
  29. if content == "" {
  30. println("need a valid -config option")
  31. return false
  32. }
  33. if *outputPath != "" {
  34. ioutil.WriteFile(filepath.Join(*outputPath, *config+".toml"), []byte(content), 0644)
  35. } else {
  36. println(content)
  37. }
  38. return true
  39. }
  40. const (
  41. FILER_TOML_EXAMPLE = `
  42. # A sample TOML config file for SeaweedFS filer store
  43. # Used with "weed filer" or "weed server -filer"
  44. # Put this file to one of the location, with descending priority
  45. # ./filer.toml
  46. # $HOME/.seaweedfs/filer.toml
  47. # /etc/seaweedfs/filer.toml
  48. [memory]
  49. # local in memory, mostly for testing purpose
  50. enabled = false
  51. [leveldb]
  52. # local on disk, mostly for simple single-machine setup, fairly scalable
  53. enabled = true
  54. dir = "." # directory to store level db files
  55. ####################################################
  56. # multiple filers on shared storage, fairly scalable
  57. ####################################################
  58. [mysql]
  59. # CREATE TABLE IF NOT EXISTS filemeta (
  60. # dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
  61. # name VARCHAR(1000) COMMENT 'directory or file name',
  62. # directory VARCHAR(4096) COMMENT 'full path to parent directory',
  63. # meta BLOB,
  64. # PRIMARY KEY (dirhash, name)
  65. # ) DEFAULT CHARSET=utf8;
  66. enabled = false
  67. hostname = "localhost"
  68. port = 3306
  69. username = "root"
  70. password = ""
  71. database = "" # create or use an existing database
  72. connection_max_idle = 2
  73. connection_max_open = 100
  74. [postgres]
  75. # CREATE TABLE IF NOT EXISTS filemeta (
  76. # dirhash BIGINT,
  77. # name VARCHAR(1000),
  78. # directory VARCHAR(4096),
  79. # meta bytea,
  80. # PRIMARY KEY (dirhash, name)
  81. # );
  82. enabled = false
  83. hostname = "localhost"
  84. port = 5432
  85. username = "postgres"
  86. password = ""
  87. database = "" # create or use an existing database
  88. sslmode = "disable"
  89. connection_max_idle = 100
  90. connection_max_open = 100
  91. [cassandra]
  92. # CREATE TABLE filemeta (
  93. # directory varchar,
  94. # name varchar,
  95. # meta blob,
  96. # PRIMARY KEY (directory, name)
  97. # ) WITH CLUSTERING ORDER BY (name ASC);
  98. enabled = false
  99. keyspace="seaweedfs"
  100. hosts=[
  101. "localhost:9042",
  102. ]
  103. [redis]
  104. enabled = false
  105. address = "localhost:6379"
  106. password = ""
  107. db = 0
  108. [redis_cluster]
  109. enabled = false
  110. addresses = [
  111. "localhost:30001",
  112. "localhost:30002",
  113. "localhost:30003",
  114. "localhost:30004",
  115. "localhost:30005",
  116. "localhost:30006",
  117. ]
  118. `
  119. NOTIFICATION_TOML_EXAMPLE = `
  120. # A sample TOML config file for SeaweedFS filer store
  121. # Used by both "weed filer" or "weed server -filer" and "weed filer.replicate"
  122. # Put this file to one of the location, with descending priority
  123. # ./notification.toml
  124. # $HOME/.seaweedfs/notification.toml
  125. # /etc/seaweedfs/notification.toml
  126. ####################################################
  127. # notification
  128. # send and receive filer updates for each file to an external message queue
  129. ####################################################
  130. [notification.log]
  131. # this is only for debugging perpose and does not work with "weed filer.replicate"
  132. enabled = false
  133. [notification.kafka]
  134. enabled = false
  135. hosts = [
  136. "localhost:9092"
  137. ]
  138. topic = "seaweedfs_filer"
  139. offsetFile = "./last.offset"
  140. offsetSaveIntervalSeconds = 10
  141. [notification.aws_sqs]
  142. # experimental, let me know if it works
  143. enabled = false
  144. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  145. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  146. region = "us-east-2"
  147. sqs_queue_name = "my_filer_queue" # an existing queue name
  148. [notification.google_pub_sub]
  149. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  150. enabled = false
  151. google_application_credentials = "/path/to/x.json" # path to json credential file
  152. project_id = "" # an existing project id
  153. topic = "seaweedfs_filer_topic" # a topic, auto created if does not exists
  154. `
  155. REPLICATION_TOML_EXAMPLE = `
  156. # A sample TOML config file for replicating SeaweedFS filer
  157. # Used with "weed filer.replicate"
  158. # Put this file to one of the location, with descending priority
  159. # ./replication.toml
  160. # $HOME/.seaweedfs/replication.toml
  161. # /etc/seaweedfs/replication.toml
  162. [source.filer]
  163. enabled = true
  164. grpcAddress = "localhost:18888"
  165. # all files under this directory tree are replicated.
  166. # this is not a directory on your hard drive, but on your filer.
  167. # i.e., all files with this "prefix" are sent to notification message queue.
  168. directory = "/buckets"
  169. [sink.filer]
  170. enabled = false
  171. grpcAddress = "localhost:18888"
  172. # all replicated files are under this directory tree
  173. # this is not a directory on your hard drive, but on your filer.
  174. # i.e., all received files will be "prefixed" to this directory.
  175. directory = "/backup"
  176. replication = ""
  177. collection = ""
  178. ttlSec = 0
  179. [sink.s3]
  180. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  181. # default loads credentials from the shared credentials file (~/.aws/credentials).
  182. enabled = false
  183. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  184. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  185. region = "us-east-2"
  186. bucket = "your_bucket_name" # an existing bucket
  187. directory = "/" # destination directory
  188. [sink.google_cloud_storage]
  189. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  190. enabled = false
  191. google_application_credentials = "/path/to/x.json" # path to json credential file
  192. bucket = "your_bucket_seaweedfs" # an existing bucket
  193. directory = "/" # destination directory
  194. [sink.azure]
  195. # experimental, let me know if it works
  196. enabled = false
  197. account_name = ""
  198. account_key = ""
  199. container = "mycontainer" # an existing container
  200. directory = "/" # destination directory
  201. [sink.backblaze]
  202. enabled = false
  203. b2_account_id = ""
  204. b2_master_application_key = ""
  205. bucket = "mybucket" # an existing bucket
  206. directory = "/" # destination directory
  207. `
  208. )