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.

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