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.

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