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.

105 lines
3.8 KiB

11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. package command
  2. import (
  3. "net/http"
  4. "os"
  5. "strconv"
  6. "time"
  7. "github.com/chrislusf/seaweedfs/weed/glog"
  8. "github.com/chrislusf/seaweedfs/weed/server"
  9. "github.com/chrislusf/seaweedfs/weed/util"
  10. )
  11. var (
  12. f FilerOptions
  13. )
  14. type FilerOptions struct {
  15. master *string
  16. ip *string
  17. port *int
  18. collection *string
  19. defaultReplicaPlacement *string
  20. dir *string
  21. redirectOnRead *bool
  22. disableDirListing *bool
  23. secretKey *string
  24. cassandra_server *string
  25. cassandra_keyspace *string
  26. redis_server *string
  27. redis_password *string
  28. redis_database *int
  29. }
  30. func init() {
  31. cmdFiler.Run = runFiler // break init cycle
  32. f.master = cmdFiler.Flag.String("master", "localhost:9333", "master server location")
  33. f.collection = cmdFiler.Flag.String("collection", "", "all data will be stored in this collection")
  34. f.ip = cmdFiler.Flag.String("ip", "", "filer server http listen ip address")
  35. f.port = cmdFiler.Flag.Int("port", 8888, "filer server http listen port")
  36. f.dir = cmdFiler.Flag.String("dir", os.TempDir(), "directory to store meta data")
  37. f.defaultReplicaPlacement = cmdFiler.Flag.String("defaultReplicaPlacement", "000", "default replication type if not specified")
  38. f.redirectOnRead = cmdFiler.Flag.Bool("redirectOnRead", false, "whether proxy or redirect to volume server during file GET request")
  39. f.disableDirListing = cmdFiler.Flag.Bool("disableDirListing", false, "turn off directory listing")
  40. f.cassandra_server = cmdFiler.Flag.String("cassandra.server", "", "host[:port] of the cassandra server")
  41. f.cassandra_keyspace = cmdFiler.Flag.String("cassandra.keyspace", "seaweed", "keyspace of the cassandra server")
  42. f.redis_server = cmdFiler.Flag.String("redis.server", "", "host:port of the redis server, e.g., 127.0.0.1:6379")
  43. f.redis_password = cmdFiler.Flag.String("redis.password", "", "password in clear text")
  44. f.redis_database = cmdFiler.Flag.Int("redis.database", 0, "the database on the redis server")
  45. f.secretKey = cmdFiler.Flag.String("secure.secret", "", "secret to encrypt Json Web Token(JWT)")
  46. }
  47. var cmdFiler = &Command{
  48. UsageLine: "filer -port=8888 -dir=/tmp -master=<ip:port>",
  49. Short: "start a file server that points to a master server",
  50. Long: `start a file server which accepts REST operation for any files.
  51. //create or overwrite the file, the directories /path/to will be automatically created
  52. POST /path/to/file
  53. //get the file content
  54. GET /path/to/file
  55. //create or overwrite the file, the filename in the multipart request will be used
  56. POST /path/to/
  57. //return a json format subdirectory and files listing
  58. GET /path/to/
  59. Current <fullpath~fileid> mapping metadata store is local embedded leveldb.
  60. It should be highly scalable to hundreds of millions of files on a modest machine.
  61. Future we will ensure it can avoid of being SPOF.
  62. `,
  63. }
  64. func runFiler(cmd *Command, args []string) bool {
  65. if err := util.TestFolderWritable(*f.dir); err != nil {
  66. glog.Fatalf("Check Meta Folder (-dir) Writable %s : %s", *f.dir, err)
  67. }
  68. r := http.NewServeMux()
  69. _, nfs_err := weed_server.NewFilerServer(r, *f.ip, *f.port, *f.master, *f.dir, *f.collection,
  70. *f.defaultReplicaPlacement, *f.redirectOnRead, *f.disableDirListing,
  71. *f.secretKey,
  72. *f.cassandra_server, *f.cassandra_keyspace,
  73. *f.redis_server, *f.redis_password, *f.redis_database,
  74. )
  75. if nfs_err != nil {
  76. glog.Fatalf("Filer startup error: %v", nfs_err)
  77. }
  78. glog.V(0).Infoln("Start Seaweed Filer", util.VERSION, "at port", strconv.Itoa(*f.port))
  79. filerListener, e := util.NewListener(
  80. ":"+strconv.Itoa(*f.port),
  81. time.Duration(10)*time.Second,
  82. )
  83. if e != nil {
  84. glog.Fatalf("Filer listener error: %v", e)
  85. }
  86. if e := http.Serve(filerListener, r); e != nil {
  87. glog.Fatalf("Filer Fail to serve: %v", e)
  88. }
  89. return true
  90. }