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.

303 lines
8.3 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(65535) COMMENT 'directory or file name',
  64. # directory VARCHAR(65535) 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(65535),
  80. # directory VARCHAR(65535),
  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. [notification.gocdk_pub_sub]
  157. # The Go Cloud Development Kit (https://gocloud.dev).
  158. # PubSub API (https://godoc.org/gocloud.dev/pubsub).
  159. # Supports AWS SNS/SQS, Azure Service Bus, Google PubSub, NATS and RabbitMQ.
  160. enabled = false
  161. # This URL will Dial the RabbitMQ server at the URL in the environment
  162. # variable RABBIT_SERVER_URL and open the exchange "myexchange".
  163. # The exchange must have already been created by some other means, like
  164. # the RabbitMQ management plugin.
  165. topic_url = "rabbit://myexchange"
  166. `
  167. REPLICATION_TOML_EXAMPLE = `
  168. # A sample TOML config file for replicating SeaweedFS filer
  169. # Used with "weed filer.replicate"
  170. # Put this file to one of the location, with descending priority
  171. # ./replication.toml
  172. # $HOME/.seaweedfs/replication.toml
  173. # /etc/seaweedfs/replication.toml
  174. [source.filer]
  175. enabled = true
  176. grpcAddress = "localhost:18888"
  177. # all files under this directory tree are replicated.
  178. # this is not a directory on your hard drive, but on your filer.
  179. # i.e., all files with this "prefix" are sent to notification message queue.
  180. directory = "/buckets"
  181. [sink.filer]
  182. enabled = false
  183. grpcAddress = "localhost:18888"
  184. # all replicated files are under this directory tree
  185. # this is not a directory on your hard drive, but on your filer.
  186. # i.e., all received files will be "prefixed" to this directory.
  187. directory = "/backup"
  188. replication = ""
  189. collection = ""
  190. ttlSec = 0
  191. [sink.s3]
  192. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  193. # default loads credentials from the shared credentials file (~/.aws/credentials).
  194. enabled = false
  195. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  196. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  197. region = "us-east-2"
  198. bucket = "your_bucket_name" # an existing bucket
  199. directory = "/" # destination directory
  200. [sink.google_cloud_storage]
  201. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  202. enabled = false
  203. google_application_credentials = "/path/to/x.json" # path to json credential file
  204. bucket = "your_bucket_seaweedfs" # an existing bucket
  205. directory = "/" # destination directory
  206. [sink.azure]
  207. # experimental, let me know if it works
  208. enabled = false
  209. account_name = ""
  210. account_key = ""
  211. container = "mycontainer" # an existing container
  212. directory = "/" # destination directory
  213. [sink.backblaze]
  214. enabled = false
  215. b2_account_id = ""
  216. b2_master_application_key = ""
  217. bucket = "mybucket" # an existing bucket
  218. directory = "/" # destination directory
  219. `
  220. SECURITY_TOML_EXAMPLE = `
  221. # Put this file to one of the location, with descending priority
  222. # ./security.toml
  223. # $HOME/.seaweedfs/security.toml
  224. # /etc/seaweedfs/security.toml
  225. # this file is read by master, volume server, and filer
  226. # the jwt signing key is read by master and volume server
  227. # a jwt expires in 10 seconds
  228. [jwt.signing]
  229. key = ""
  230. # all grpc tls authentications are mutual
  231. # the values for the following ca, cert, and key are paths to the PERM files.
  232. [grpc]
  233. ca = ""
  234. [grpc.volume]
  235. cert = ""
  236. key = ""
  237. [grpc.master]
  238. cert = ""
  239. key = ""
  240. [grpc.filer]
  241. cert = ""
  242. key = ""
  243. # use this for any place needs a grpc client
  244. # i.e., "weed backup|benchmark|filer.copy|filer.replicate|mount|s3|upload"
  245. [grpc.client]
  246. cert = ""
  247. key = ""
  248. # volume server https options
  249. # Note: work in progress!
  250. # this does not work with other clients, e.g., "weed filer|mount" etc, yet.
  251. [https.client]
  252. enabled = true
  253. [https.volume]
  254. cert = ""
  255. key = ""
  256. `
  257. )