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.

312 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. `
  126. NOTIFICATION_TOML_EXAMPLE = `
  127. # A sample TOML config file for SeaweedFS filer store
  128. # Used by both "weed filer" or "weed server -filer" and "weed filer.replicate"
  129. # Put this file to one of the location, with descending priority
  130. # ./notification.toml
  131. # $HOME/.seaweedfs/notification.toml
  132. # /etc/seaweedfs/notification.toml
  133. ####################################################
  134. # notification
  135. # send and receive filer updates for each file to an external message queue
  136. ####################################################
  137. [notification.log]
  138. # this is only for debugging perpose and does not work with "weed filer.replicate"
  139. enabled = false
  140. [notification.kafka]
  141. enabled = false
  142. hosts = [
  143. "localhost:9092"
  144. ]
  145. topic = "seaweedfs_filer"
  146. offsetFile = "./last.offset"
  147. offsetSaveIntervalSeconds = 10
  148. [notification.aws_sqs]
  149. # experimental, let me know if it works
  150. enabled = false
  151. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  152. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  153. region = "us-east-2"
  154. sqs_queue_name = "my_filer_queue" # an existing queue name
  155. [notification.google_pub_sub]
  156. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  157. enabled = false
  158. google_application_credentials = "/path/to/x.json" # path to json credential file
  159. project_id = "" # an existing project id
  160. topic = "seaweedfs_filer_topic" # a topic, auto created if does not exists
  161. [notification.gocdk_pub_sub]
  162. # The Go Cloud Development Kit (https://gocloud.dev).
  163. # PubSub API (https://godoc.org/gocloud.dev/pubsub).
  164. # Supports AWS SNS/SQS, Azure Service Bus, Google PubSub, NATS and RabbitMQ.
  165. enabled = false
  166. # This URL will Dial the RabbitMQ server at the URL in the environment
  167. # variable RABBIT_SERVER_URL and open the exchange "myexchange".
  168. # The exchange must have already been created by some other means, like
  169. # the RabbitMQ management plugin.
  170. topic_url = "rabbit://myexchange"
  171. sub_url = "rabbit://myqueue"
  172. `
  173. REPLICATION_TOML_EXAMPLE = `
  174. # A sample TOML config file for replicating SeaweedFS filer
  175. # Used with "weed filer.replicate"
  176. # Put this file to one of the location, with descending priority
  177. # ./replication.toml
  178. # $HOME/.seaweedfs/replication.toml
  179. # /etc/seaweedfs/replication.toml
  180. [source.filer]
  181. enabled = true
  182. grpcAddress = "localhost:18888"
  183. # all files under this directory tree are replicated.
  184. # this is not a directory on your hard drive, but on your filer.
  185. # i.e., all files with this "prefix" are sent to notification message queue.
  186. directory = "/buckets"
  187. [sink.filer]
  188. enabled = false
  189. grpcAddress = "localhost:18888"
  190. # all replicated files are under this directory tree
  191. # this is not a directory on your hard drive, but on your filer.
  192. # i.e., all received files will be "prefixed" to this directory.
  193. directory = "/backup"
  194. replication = ""
  195. collection = ""
  196. ttlSec = 0
  197. [sink.s3]
  198. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  199. # default loads credentials from the shared credentials file (~/.aws/credentials).
  200. enabled = false
  201. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  202. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  203. region = "us-east-2"
  204. bucket = "your_bucket_name" # an existing bucket
  205. directory = "/" # destination directory
  206. [sink.google_cloud_storage]
  207. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  208. enabled = false
  209. google_application_credentials = "/path/to/x.json" # path to json credential file
  210. bucket = "your_bucket_seaweedfs" # an existing bucket
  211. directory = "/" # destination directory
  212. [sink.azure]
  213. # experimental, let me know if it works
  214. enabled = false
  215. account_name = ""
  216. account_key = ""
  217. container = "mycontainer" # an existing container
  218. directory = "/" # destination directory
  219. [sink.backblaze]
  220. enabled = false
  221. b2_account_id = ""
  222. b2_master_application_key = ""
  223. bucket = "mybucket" # an existing bucket
  224. directory = "/" # destination directory
  225. `
  226. SECURITY_TOML_EXAMPLE = `
  227. # Put this file to one of the location, with descending priority
  228. # ./security.toml
  229. # $HOME/.seaweedfs/security.toml
  230. # /etc/seaweedfs/security.toml
  231. # this file is read by master, volume server, and filer
  232. # the jwt signing key is read by master and volume server.
  233. # a jwt defaults to expire after 10 seconds.
  234. [jwt.signing]
  235. key = ""
  236. expires_after_seconds = 10 # seconds
  237. # all grpc tls authentications are mutual
  238. # the values for the following ca, cert, and key are paths to the PERM files.
  239. [grpc]
  240. ca = ""
  241. [grpc.volume]
  242. cert = ""
  243. key = ""
  244. [grpc.master]
  245. cert = ""
  246. key = ""
  247. [grpc.filer]
  248. cert = ""
  249. key = ""
  250. # use this for any place needs a grpc client
  251. # i.e., "weed backup|benchmark|filer.copy|filer.replicate|mount|s3|upload"
  252. [grpc.client]
  253. cert = ""
  254. key = ""
  255. # volume server https options
  256. # Note: work in progress!
  257. # this does not work with other clients, e.g., "weed filer|mount" etc, yet.
  258. [https.client]
  259. enabled = true
  260. [https.volume]
  261. cert = ""
  262. key = ""
  263. `
  264. )