weedfuse: adapt to fstab command line pattern
This commit is contained in:
84
weed/command/weedfuse/README.md
Normal file
84
weed/command/weedfuse/README.md
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
Mount the SeaweedFS via FUSE
|
||||||
|
|
||||||
|
# Mount by fstab
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
$ # on linux
|
||||||
|
$ sudo apt-get install fuse
|
||||||
|
$ sudo echo 'user_allow_other' >> /etc/fuse.conf
|
||||||
|
$ sudo mv weedfuse /sbin/mount.weedfuse
|
||||||
|
|
||||||
|
$ # on Mac
|
||||||
|
$ sudo mv weedfuse /sbin/mount_weedfuse
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
On both OS X and Linux, you can add one of the entries to your /etc/fstab file like the following:
|
||||||
|
|
||||||
|
```
|
||||||
|
# mount the whole SeaweedFS
|
||||||
|
localhost:8888/ /home/some/mount/folder weedfuse
|
||||||
|
|
||||||
|
# mount the SeaweedFS sub folder
|
||||||
|
localhost:8888/sub/dir /home/some/mount/folder weedfuse
|
||||||
|
|
||||||
|
# mount the SeaweedFS sub folder with some options
|
||||||
|
localhost:8888/sub/dir /home/some/mount/folder weedfuse user
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
To verify it can work, try this command
|
||||||
|
```
|
||||||
|
$ sudo mount -av
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
/home/some/mount/folder : successfully mounted
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
If you see `successfully mounted`, try to access the mounted folder and verify everything works.
|
||||||
|
|
||||||
|
|
||||||
|
To debug, run these:
|
||||||
|
```
|
||||||
|
|
||||||
|
$ weedfuse -foreground localhost:8888/ /home/some/mount/folder
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
To unmount the folder:
|
||||||
|
```
|
||||||
|
|
||||||
|
$ sudo umount /home/some/mount/folder
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
<!-- not working yet!
|
||||||
|
|
||||||
|
# Mount by autofs
|
||||||
|
|
||||||
|
AutoFS can mount a folder if accessed.
|
||||||
|
|
||||||
|
```
|
||||||
|
# install autofs
|
||||||
|
$ sudo apt-get install autofs
|
||||||
|
```
|
||||||
|
|
||||||
|
Here is an example on how to mount a folder for all users under `/home` directory.
|
||||||
|
Assuming there exists corresponding folders under `/home` on both local and SeaweedFS.
|
||||||
|
|
||||||
|
Edit `/etc/auto.master` and `/etc/auto.weedfuse` file with these content
|
||||||
|
```
|
||||||
|
$ cat /etc/auto.master
|
||||||
|
/home /etc/auto.weedfuse
|
||||||
|
|
||||||
|
$ cat /etc/auto.weedfuse
|
||||||
|
# map /home/<user> to localhost:8888/home/<user>
|
||||||
|
* -fstype=weedfuse,rw,allow_other,foreground :localhost\:8888/home/&
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
-->
|
||||||
@@ -13,20 +13,45 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
options = flag.String("o", "", "comma separated options rw,uid=xxx,gid=xxx")
|
fuseCommand = flag.NewFlagSet("weedfuse", flag.ContinueOnError)
|
||||||
isForeground = flag.Bool("foreground", false, "starts as a daemon")
|
options = fuseCommand.String("o", "", "comma separated options rw,uid=xxx,gid=xxx")
|
||||||
|
isForeground = fuseCommand.Bool("foreground", false, "starts as a daemon")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
flag.Parse()
|
err := fuseCommand.Parse(os.Args[1:])
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("options: %v\n", *options)
|
||||||
|
|
||||||
device := flag.Arg(0)
|
// seems this value is always empty, need to parse it differently
|
||||||
mountPoint := flag.Arg(1)
|
optionsString := *options
|
||||||
|
prev := ""
|
||||||
|
for i, arg := range os.Args {
|
||||||
|
fmt.Printf("args[%d]: %v\n", i, arg)
|
||||||
|
if prev == "-o" {
|
||||||
|
optionsString = arg
|
||||||
|
}
|
||||||
|
prev = arg
|
||||||
|
}
|
||||||
|
|
||||||
|
device := fuseCommand.Arg(0)
|
||||||
|
mountPoint := fuseCommand.Arg(1)
|
||||||
|
|
||||||
fmt.Printf("source: %v\n", device)
|
fmt.Printf("source: %v\n", device)
|
||||||
fmt.Printf("target: %v\n", mountPoint)
|
fmt.Printf("target: %v\n", mountPoint)
|
||||||
|
|
||||||
|
nouser := true
|
||||||
|
for _, option := range strings.Split(optionsString, ",") {
|
||||||
|
fmt.Printf("option: %v\n", option)
|
||||||
|
switch option {
|
||||||
|
case "user":
|
||||||
|
nouser = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
maybeSetupPath()
|
maybeSetupPath()
|
||||||
|
|
||||||
if !*isForeground {
|
if !*isForeground {
|
||||||
@@ -39,7 +64,7 @@ func main() {
|
|||||||
|
|
||||||
command.RunMount(
|
command.RunMount(
|
||||||
filer, "/"+filerPath, mountPoint, "", "000", "",
|
filer, "/"+filerPath, mountPoint, "", "000", "",
|
||||||
4, true, 0, 1000000)
|
4, !nouser, 0, 1000000)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user