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.

85 lines
2.6 KiB

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