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.

79 lines
2.4 KiB

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