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.

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