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.

313 lines
8.6 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 = false
  56. dir = "." # directory to store level db files
  57. [leveldb2]
  58. # local on disk, mostly for simple single-machine setup, fairly scalable
  59. # faster than previous leveldb, recommended.
  60. enabled = true
  61. dir = "." # directory to store level db files
  62. ####################################################
  63. # multiple filers on shared storage, fairly scalable
  64. ####################################################
  65. [mysql]
  66. # CREATE TABLE IF NOT EXISTS filemeta (
  67. # dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
  68. # name VARCHAR(1000) COMMENT 'directory or file name',
  69. # directory TEXT COMMENT 'full path to parent directory',
  70. # meta LONGBLOB,
  71. # PRIMARY KEY (dirhash, name)
  72. # ) DEFAULT CHARSET=utf8;
  73. enabled = false
  74. hostname = "localhost"
  75. port = 3306
  76. username = "root"
  77. password = ""
  78. database = "" # create or use an existing database
  79. connection_max_idle = 2
  80. connection_max_open = 100
  81. [postgres]
  82. # CREATE TABLE IF NOT EXISTS filemeta (
  83. # dirhash BIGINT,
  84. # name VARCHAR(65535),
  85. # directory VARCHAR(65535),
  86. # meta bytea,
  87. # PRIMARY KEY (dirhash, name)
  88. # );
  89. enabled = false
  90. hostname = "localhost"
  91. port = 5432
  92. username = "postgres"
  93. password = ""
  94. database = "" # create or use an existing database
  95. sslmode = "disable"
  96. connection_max_idle = 100
  97. connection_max_open = 100
  98. [cassandra]
  99. # CREATE TABLE filemeta (
  100. # directory varchar,
  101. # name varchar,
  102. # meta blob,
  103. # PRIMARY KEY (directory, name)
  104. # ) WITH CLUSTERING ORDER BY (name ASC);
  105. enabled = false
  106. keyspace="seaweedfs"
  107. hosts=[
  108. "localhost:9042",
  109. ]
  110. [redis]
  111. enabled = false
  112. address = "localhost:6379"
  113. password = ""
  114. db = 0
  115. [redis_cluster]
  116. enabled = false
  117. addresses = [
  118. "localhost:30001",
  119. "localhost:30002",
  120. "localhost:30003",
  121. "localhost:30004",
  122. "localhost:30005",
  123. "localhost:30006",
  124. ]
  125. password = ""
  126. `
  127. NOTIFICATION_TOML_EXAMPLE = `
  128. # A sample TOML config file for SeaweedFS filer store
  129. # Used by both "weed filer" or "weed server -filer" and "weed filer.replicate"
  130. # Put this file to one of the location, with descending priority
  131. # ./notification.toml
  132. # $HOME/.seaweedfs/notification.toml
  133. # /etc/seaweedfs/notification.toml
  134. ####################################################
  135. # notification
  136. # send and receive filer updates for each file to an external message queue
  137. ####################################################
  138. [notification.log]
  139. # this is only for debugging perpose and does not work with "weed filer.replicate"
  140. enabled = false
  141. [notification.kafka]
  142. enabled = false
  143. hosts = [
  144. "localhost:9092"
  145. ]
  146. topic = "seaweedfs_filer"
  147. offsetFile = "./last.offset"
  148. offsetSaveIntervalSeconds = 10
  149. [notification.aws_sqs]
  150. # experimental, let me know if it works
  151. enabled = false
  152. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  153. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  154. region = "us-east-2"
  155. sqs_queue_name = "my_filer_queue" # an existing queue name
  156. [notification.google_pub_sub]
  157. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  158. enabled = false
  159. google_application_credentials = "/path/to/x.json" # path to json credential file
  160. project_id = "" # an existing project id
  161. topic = "seaweedfs_filer_topic" # a topic, auto created if does not exists
  162. [notification.gocdk_pub_sub]
  163. # The Go Cloud Development Kit (https://gocloud.dev).
  164. # PubSub API (https://godoc.org/gocloud.dev/pubsub).
  165. # Supports AWS SNS/SQS, Azure Service Bus, Google PubSub, NATS and RabbitMQ.
  166. enabled = false
  167. # This URL will Dial the RabbitMQ server at the URL in the environment
  168. # variable RABBIT_SERVER_URL and open the exchange "myexchange".
  169. # The exchange must have already been created by some other means, like
  170. # the RabbitMQ management plugin.
  171. topic_url = "rabbit://myexchange"
  172. sub_url = "rabbit://myqueue"
  173. `
  174. REPLICATION_TOML_EXAMPLE = `
  175. # A sample TOML config file for replicating SeaweedFS filer
  176. # Used with "weed filer.replicate"
  177. # Put this file to one of the location, with descending priority
  178. # ./replication.toml
  179. # $HOME/.seaweedfs/replication.toml
  180. # /etc/seaweedfs/replication.toml
  181. [source.filer]
  182. enabled = true
  183. grpcAddress = "localhost:18888"
  184. # all files under this directory tree are replicated.
  185. # this is not a directory on your hard drive, but on your filer.
  186. # i.e., all files with this "prefix" are sent to notification message queue.
  187. directory = "/buckets"
  188. [sink.filer]
  189. enabled = false
  190. grpcAddress = "localhost:18888"
  191. # all replicated files are under this directory tree
  192. # this is not a directory on your hard drive, but on your filer.
  193. # i.e., all received files will be "prefixed" to this directory.
  194. directory = "/backup"
  195. replication = ""
  196. collection = ""
  197. ttlSec = 0
  198. [sink.s3]
  199. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  200. # default loads credentials from the shared credentials file (~/.aws/credentials).
  201. enabled = false
  202. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  203. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  204. region = "us-east-2"
  205. bucket = "your_bucket_name" # an existing bucket
  206. directory = "/" # destination directory
  207. [sink.google_cloud_storage]
  208. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  209. enabled = false
  210. google_application_credentials = "/path/to/x.json" # path to json credential file
  211. bucket = "your_bucket_seaweedfs" # an existing bucket
  212. directory = "/" # destination directory
  213. [sink.azure]
  214. # experimental, let me know if it works
  215. enabled = false
  216. account_name = ""
  217. account_key = ""
  218. container = "mycontainer" # an existing container
  219. directory = "/" # destination directory
  220. [sink.backblaze]
  221. enabled = false
  222. b2_account_id = ""
  223. b2_master_application_key = ""
  224. bucket = "mybucket" # an existing bucket
  225. directory = "/" # destination directory
  226. `
  227. SECURITY_TOML_EXAMPLE = `
  228. # Put this file to one of the location, with descending priority
  229. # ./security.toml
  230. # $HOME/.seaweedfs/security.toml
  231. # /etc/seaweedfs/security.toml
  232. # this file is read by master, volume server, and filer
  233. # the jwt signing key is read by master and volume server.
  234. # a jwt defaults to expire after 10 seconds.
  235. [jwt.signing]
  236. key = ""
  237. expires_after_seconds = 10 # seconds
  238. # all grpc tls authentications are mutual
  239. # the values for the following ca, cert, and key are paths to the PERM files.
  240. [grpc]
  241. ca = ""
  242. [grpc.volume]
  243. cert = ""
  244. key = ""
  245. [grpc.master]
  246. cert = ""
  247. key = ""
  248. [grpc.filer]
  249. cert = ""
  250. key = ""
  251. # use this for any place needs a grpc client
  252. # i.e., "weed backup|benchmark|filer.copy|filer.replicate|mount|s3|upload"
  253. [grpc.client]
  254. cert = ""
  255. key = ""
  256. # volume server https options
  257. # Note: work in progress!
  258. # this does not work with other clients, e.g., "weed filer|mount" etc, yet.
  259. [https.client]
  260. enabled = true
  261. [https.volume]
  262. cert = ""
  263. key = ""
  264. `
  265. )