diff --git a/cmd/mount.go b/cmd/mount.go index cc0769daf501..b0346330d855 100644 --- a/cmd/mount.go +++ b/cmd/mount.go @@ -30,8 +30,8 @@ import ( "syscall" "time" - "github.com/VividCortex/godaemon" "github.com/google/gops/agent" + "github.com/juicedata/godaemon" "github.com/urfave/cli/v2" "github.com/juicedata/juicefs/pkg/chunk" @@ -41,8 +41,8 @@ import ( "github.com/juicedata/juicefs/pkg/vfs" ) -func MakeDaemon() error { - _, _, err := godaemon.MakeDaemon(&godaemon.DaemonAttr{}) +func MakeDaemon(onExit func(int) error) error { + _, _, err := godaemon.MakeDaemon(&godaemon.DaemonAttr{OnExit: onExit}) return err } @@ -136,10 +136,26 @@ func mount(c *cli.Context) error { logger.Fatalf("object storage: %s", err) } logger.Infof("Data use %s", blob) - logger.Infof("mount volume %s at %s", format.Name, mp) + logger.Infof("Mounting volume %s at %s ...", format.Name, mp) if c.Bool("background") { - if err := MakeDaemon(); err != nil { + err := MakeDaemon(func(stage int) error { + if stage != 0 { + return nil + } + for { + time.Sleep(time.Millisecond * 50) + st, err := os.Stat(mp) + if err == nil { + if sys, ok := st.Sys().(*syscall.Stat_t); ok && sys.Ino == 1 { + logger.Infof("\033[92mOK\033[0m, %s is ready at %s", format.Name, mp) + break + } + } + } + return nil + }) + if err != nil { logger.Fatalf("Failed to make daemon: %s", err) } } diff --git a/fstests/Makefile b/fstests/Makefile index 0b7572b9c3e9..556ef9838d8d 100644 --- a/fstests/Makefile +++ b/fstests/Makefile @@ -19,7 +19,7 @@ setup: redis-server & mkdir -p /jfs ../juicefs format -storage mem localhost unittest - ../juicefs mount --no-usage-report --enable-xattr localhost /jfs & + ../juicefs mount -d --no-usage-report --enable-xattr localhost /jfs healthcheck: pgrep juicefs diff --git a/go.mod b/go.mod index dda8f671be5d..8928c0067f3d 100644 --- a/go.mod +++ b/go.mod @@ -4,13 +4,13 @@ go 1.13 require ( github.com/DataDog/zstd v1.4.5 - github.com/VividCortex/godaemon v0.0.0-20201215173923-eda977734e72 github.com/ceph/go-ceph v0.4.0 github.com/go-redis/redis/v8 v8.4.0 github.com/google/gops v0.3.13 github.com/google/uuid v1.1.1 github.com/hanwen/go-fuse/v2 v2.0.4-0.20210104155004-09a3c381714c github.com/hungys/go-lz4 v0.0.0-20170805124057-19ff7f07f099 + github.com/juicedata/godaemon v0.0.0-20210118074000-659b6681b236 github.com/juicedata/juicesync v0.6.3-0.20210114082630-137546625adb github.com/sirupsen/logrus v1.7.0 github.com/urfave/cli/v2 v2.3.0 diff --git a/go.sum b/go.sum index ee2c055b773d..e6b056a2735f 100644 --- a/go.sum +++ b/go.sum @@ -111,6 +111,10 @@ github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2 github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/juicedata/godaemon v0.0.0-20201215173923-eda977734e72 h1:JjGhjAtHA3UQiz3QqrIh31t1LlPI6R54aDrBWSPjfQo= +github.com/juicedata/godaemon v0.0.0-20201215173923-eda977734e72/go.mod h1:dlxKkLh3qAIPtgr2U/RVzsZJDuXA1ffg+Njikfmhvgw= +github.com/juicedata/godaemon v0.0.0-20210118074000-659b6681b236 h1:py4S1ZTRfz5hIvrhu83YSw7t0Z621+VrmmZBqSkQn5c= +github.com/juicedata/godaemon v0.0.0-20210118074000-659b6681b236/go.mod h1:dlxKkLh3qAIPtgr2U/RVzsZJDuXA1ffg+Njikfmhvgw= github.com/juicedata/juicesync v0.6.3-0.20210105123925-2af95f8a8472 h1:4IWRyIhlkU2+0UhJcVdLfwjxnBMSj91TIgDN/2E0ikM= github.com/juicedata/juicesync v0.6.3-0.20210105123925-2af95f8a8472/go.mod h1:PTOFdso2hrHXU4RctCWgbSysCclKAjcAU311/z55lUE= github.com/juicedata/juicesync v0.6.3-0.20210114024648-941ff49f2eb3 h1:JRC/u/wKZvL1Et7vQ5G3uOdy5xWuEYPa/sdnwYt7TmI=