forked from TrueCloudLab/rclone
mount: use sdnotify to signal systemd the mount is ready
When the NOTIFY_SOCKET environment variable is set notify systemd after the mount is ready.
This commit is contained in:
parent
0bfa29cbcf
commit
d8b3bf014d
3 changed files with 20 additions and 0 deletions
|
@ -21,6 +21,7 @@ import (
|
||||||
"github.com/ncw/rclone/fs"
|
"github.com/ncw/rclone/fs"
|
||||||
"github.com/ncw/rclone/vfs"
|
"github.com/ncw/rclone/vfs"
|
||||||
"github.com/ncw/rclone/vfs/vfsflags"
|
"github.com/ncw/rclone/vfs/vfsflags"
|
||||||
|
"github.com/okzk/sdnotify"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -180,6 +181,10 @@ func Mount(f fs.Fs, mountpoint string) error {
|
||||||
sigHup := make(chan os.Signal, 1)
|
sigHup := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigHup, syscall.SIGHUP)
|
signal.Notify(sigHup, syscall.SIGHUP)
|
||||||
|
|
||||||
|
if err := sdnotify.SdNotifyReady(); err != nil && err != sdnotify.SdNotifyNoSocket {
|
||||||
|
return errors.Wrap(err, "failed to notify systemd")
|
||||||
|
}
|
||||||
|
|
||||||
waitloop:
|
waitloop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -197,6 +202,7 @@ waitloop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ = sdnotify.SdNotifyStopping()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to umount FUSE fs")
|
return errors.Wrap(err, "failed to umount FUSE fs")
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"github.com/ncw/rclone/fs"
|
"github.com/ncw/rclone/fs"
|
||||||
"github.com/ncw/rclone/vfs"
|
"github.com/ncw/rclone/vfs"
|
||||||
"github.com/ncw/rclone/vfs/vfsflags"
|
"github.com/ncw/rclone/vfs/vfsflags"
|
||||||
|
"github.com/okzk/sdnotify"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -126,6 +127,10 @@ func Mount(f fs.Fs, mountpoint string) error {
|
||||||
sigHup := make(chan os.Signal, 1)
|
sigHup := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigHup, syscall.SIGHUP)
|
signal.Notify(sigHup, syscall.SIGHUP)
|
||||||
|
|
||||||
|
if err := sdnotify.SdNotifyReady(); err != nil && err != sdnotify.SdNotifyNoSocket {
|
||||||
|
return errors.Wrap(err, "failed to notify systemd")
|
||||||
|
}
|
||||||
|
|
||||||
waitloop:
|
waitloop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -147,6 +152,7 @@ waitloop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ = sdnotify.SdNotifyStopping()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to umount FUSE fs")
|
return errors.Wrap(err, "failed to umount FUSE fs")
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,6 +156,14 @@ Assuming only one rclone instance is running, you can reset the cache
|
||||||
like this:
|
like this:
|
||||||
|
|
||||||
kill -SIGHUP $(pidof rclone)
|
kill -SIGHUP $(pidof rclone)
|
||||||
|
|
||||||
|
### systemd ###
|
||||||
|
|
||||||
|
When running rclone ` + commandName + ` as a systemd service, it is possible
|
||||||
|
to use Type=notify. In this case the service will enter the started state
|
||||||
|
after the mountpoint has been successfully set up.
|
||||||
|
Units having the rclone ` + commandName + ` service specified as a requirement
|
||||||
|
will see all files and folders immediately in this mode.
|
||||||
`,
|
`,
|
||||||
Run: func(command *cobra.Command, args []string) {
|
Run: func(command *cobra.Command, args []string) {
|
||||||
cmd.CheckArgs(2, 2, command, args)
|
cmd.CheckArgs(2, 2, command, args)
|
||||||
|
|
Loading…
Reference in a new issue