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.

101 lines
3.5 KiB

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