seaweedfs/weed/command/scaffold.go

180 lines
4.1 KiB
Go
Raw Normal View History

2018-08-20 06:36:30 +08:00
package command
import (
"io/ioutil"
"path/filepath"
)
func init() {
cmdScaffold.Run = runScaffold // break init cycle
}
var cmdScaffold = &Command{
UsageLine: "scaffold [filer]",
Short: "generate basic configuration files",
Long: `Generate filer.toml with all possible configurations for you to customize.
`,
}
var (
outputPath = cmdScaffold.Flag.String("output", "", "if not empty, save the configuration file to this directory")
2018-09-17 15:27:56 +08:00
config = cmdScaffold.Flag.String("config", "filer", "[filer|replication] the configuration file to generate")
2018-08-20 06:36:30 +08:00
)
func runScaffold(cmd *Command, args []string) bool {
content := ""
switch *config {
case "filer":
content = FILER_TOML_EXAMPLE
2018-09-17 15:27:56 +08:00
case "replication":
content = REPLICATION_TOML_EXAMPLE
2018-08-20 06:36:30 +08:00
}
if content == "" {
println("need a valid -config option")
return false
}
if *outputPath != "" {
ioutil.WriteFile(filepath.Join(*outputPath, *config+".toml"), []byte(content), 0x755)
} else {
println(content)
}
return true
}
const (
FILER_TOML_EXAMPLE = `
# A sample TOML config file for SeaweedFS filer store
2018-09-23 13:12:06 +08:00
# Used with "weed filer" or "weed server -filer"
# Put this file to one of the location, with descending priority
# ./filer.toml
# $HOME/.seaweedfs/filer.toml
# /etc/seaweedfs/filer.toml
2018-08-20 05:58:24 +08:00
[memory]
# local in memory, mostly for testing purpose
enabled = false
[leveldb]
# local on disk, mostly for simple single-machine setup, fairly scalable
2018-08-20 06:36:30 +08:00
enabled = false
2018-08-20 05:58:24 +08:00
dir = "." # directory to store level db files
####################################################
# multiple filers on shared storage, fairly scalable
####################################################
[mysql]
# CREATE TABLE IF NOT EXISTS filemeta (
# dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
# name VARCHAR(1000) COMMENT 'directory or file name',
# directory VARCHAR(4096) COMMENT 'full path to parent directory',
# meta BLOB,
# PRIMARY KEY (dirhash, name)
# ) DEFAULT CHARSET=utf8;
2018-08-20 06:36:30 +08:00
enabled = true
2018-08-20 05:58:24 +08:00
hostname = "localhost"
port = 3306
username = "root"
password = ""
database = "" # create or use an existing database
connection_max_idle = 2
connection_max_open = 100
[postgres]
# CREATE TABLE IF NOT EXISTS filemeta (
# dirhash BIGINT,
# name VARCHAR(1000),
# directory VARCHAR(4096),
# meta bytea,
# PRIMARY KEY (dirhash, name)
# );
enabled = false
hostname = "localhost"
port = 5432
username = "postgres"
password = ""
database = "" # create or use an existing database
sslmode = "disable"
connection_max_idle = 100
connection_max_open = 100
[cassandra]
# CREATE TABLE filemeta (
# directory varchar,
# name varchar,
# meta blob,
# PRIMARY KEY (directory, name)
# ) WITH CLUSTERING ORDER BY (name ASC);
enabled = false
keyspace="seaweedfs"
hosts=[
"localhost:9042",
]
[redis]
2018-08-20 06:36:30 +08:00
enabled = true
2018-08-20 05:58:24 +08:00
address = "localhost:6379"
password = ""
db = 0
[redis_cluster]
enabled = false
addresses = [
"localhost:30001",
"localhost:30002",
"localhost:30003",
"localhost:30004",
"localhost:30005",
"localhost:30006",
2018-08-20 05:58:24 +08:00
]
2018-08-20 06:36:30 +08:00
2018-08-20 05:58:24 +08:00
####################################################
# notification
# sends filer updates for each file to an external message queue
####################################################
[notification.log]
enabled = true
[notification.kafka]
enabled = false
hosts = [
"localhost:9092"
]
topic = "seaweedfs_filer"
2018-09-17 15:27:56 +08:00
`
REPLICATION_TOML_EXAMPLE = `
2018-09-23 13:12:06 +08:00
# A sample TOML config file for replicating SeaweedFS filer
# Used with "weed filer.replicate"
# Put this file to one of the location, with descending priority
# ./replication.toml
# $HOME/.seaweedfs/replication.toml
# /etc/seaweedfs/replication.toml
2018-09-17 15:27:56 +08:00
[source.filer]
enabled = true
grpcAddress = "localhost:18888"
2018-09-17 16:37:24 +08:00
directory = "/buckets" # all files under this directory tree are replicated
2018-09-17 15:27:56 +08:00
[notification.kafka]
enabled = true
hosts = [
"localhost:9092"
]
2018-09-17 16:37:24 +08:00
topic = "seaweedfs_filer1_to_filer2"
2018-09-17 15:27:56 +08:00
[sink.filer]
enabled = true
grpcAddress = "localhost:18888"
2018-09-17 16:37:24 +08:00
directory = "/backup" # all replicated files are under this directory tree
2018-09-22 15:53:52 +08:00
replication = ""
collection = ""
ttlSec = 0
2018-09-17 15:27:56 +08:00
2018-08-20 06:36:30 +08:00
`
)