mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
weedfuse: daemonize
This commit is contained in:
parent
1ca1ec906a
commit
9a4fb14ea0
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/security"
|
"github.com/chrislusf/seaweedfs/weed/security"
|
||||||
"github.com/chrislusf/seaweedfs/weed/server"
|
"github.com/chrislusf/seaweedfs/weed/server"
|
||||||
|
"github.com/jacobsa/daemonize"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/filesys"
|
"github.com/chrislusf/seaweedfs/weed/filesys"
|
||||||
|
@ -107,6 +108,7 @@ func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCente
|
||||||
c, err := fuse.Mount(dir, options...)
|
c, err := fuse.Mount(dir, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
glog.Fatal(err)
|
||||||
|
daemonize.SignalOutcome(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +120,7 @@ func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCente
|
||||||
filerGrpcAddress, err := parseFilerGrpcAddress(filer)
|
filerGrpcAddress, err := parseFilerGrpcAddress(filer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
glog.Fatal(err)
|
||||||
|
daemonize.SignalOutcome(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +129,8 @@ func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCente
|
||||||
mountRoot = mountRoot[0 : len(mountRoot)-1]
|
mountRoot = mountRoot[0 : len(mountRoot)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
daemonize.SignalOutcome(nil)
|
||||||
|
|
||||||
err = fs.Serve(c, filesys.NewSeaweedFileSystem(&filesys.Option{
|
err = fs.Serve(c, filesys.NewSeaweedFileSystem(&filesys.Option{
|
||||||
FilerGrpcAddress: filerGrpcAddress,
|
FilerGrpcAddress: filerGrpcAddress,
|
||||||
GrpcDialOption: security.LoadClientTLS(viper.Sub("grpc"), "client"),
|
GrpcDialOption: security.LoadClientTLS(viper.Sub("grpc"), "client"),
|
||||||
|
@ -151,6 +156,7 @@ func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCente
|
||||||
<-c.Ready
|
<-c.Ready
|
||||||
if err := c.MountError; err != nil {
|
if err := c.MountError; err != nil {
|
||||||
glog.Fatal(err)
|
glog.Fatal(err)
|
||||||
|
daemonize.SignalOutcome(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -7,10 +7,14 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/command"
|
"github.com/chrislusf/seaweedfs/weed/command"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
|
"github.com/kardianos/osext"
|
||||||
|
"github.com/jacobsa/daemonize"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
options = flag.String("o", "", "comma separated options rw,uid=xxx,gid=xxx")
|
options = flag.String("o", "", "comma separated options rw,uid=xxx,gid=xxx")
|
||||||
|
isForeground = flag.Bool("foreground", false, "starts as a daemon")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -25,6 +29,11 @@ func main() {
|
||||||
|
|
||||||
maybeSetupPath()
|
maybeSetupPath()
|
||||||
|
|
||||||
|
if !*isForeground {
|
||||||
|
startAsDaemon()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
parts := strings.SplitN(device, "/", 2)
|
parts := strings.SplitN(device, "/", 2)
|
||||||
filer, filerPath := parts[0], parts[1]
|
filer, filerPath := parts[0], parts[1]
|
||||||
|
|
||||||
|
@ -47,3 +56,29 @@ func maybeSetupPath() {
|
||||||
os.Setenv("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
|
os.Setenv("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func startAsDaemon() {
|
||||||
|
|
||||||
|
// adapted from gcsfuse
|
||||||
|
|
||||||
|
// Find the executable.
|
||||||
|
var path string
|
||||||
|
path, err := osext.Executable()
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalf("osext.Executable: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up arguments. Be sure to use foreground mode.
|
||||||
|
args := append([]string{"-foreground"}, os.Args[1:]...)
|
||||||
|
|
||||||
|
// Pass along PATH so that the daemon can find fusermount on Linux.
|
||||||
|
env := []string{
|
||||||
|
fmt.Sprintf("PATH=%s", os.Getenv("PATH")),
|
||||||
|
}
|
||||||
|
|
||||||
|
err = daemonize.Run(path, args, env, os.Stdout)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalf("daemonize.Run: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue