weedfuse: daemonize
This commit is contained in:
@@ -7,10 +7,14 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/command"
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/kardianos/osext"
|
||||
"github.com/jacobsa/daemonize"
|
||||
)
|
||||
|
||||
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() {
|
||||
@@ -25,6 +29,11 @@ func main() {
|
||||
|
||||
maybeSetupPath()
|
||||
|
||||
if !*isForeground {
|
||||
startAsDaemon()
|
||||
return
|
||||
}
|
||||
|
||||
parts := strings.SplitN(device, "/", 2)
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user