systemd: Fix detection and switch to the coreos package everywhere
rather than having 2 separate libraries Signed-off-by: Anagh Kumar Baranwal <6824881+darthShadow@users.noreply.github.com>
This commit is contained in:
committed by
Nick Craig-Wood
parent
f0c774156e
commit
298c13e719
+14
-14
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/rclone/rclone/vfs/vfscommon"
|
||||
"github.com/rclone/rclone/vfs/vfsflags"
|
||||
|
||||
sysdnotify "github.com/iguanesolutions/go-systemd/v5/notify"
|
||||
"github.com/coreos/go-systemd/v22/daemon"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
@@ -222,10 +222,10 @@ func NewMountCommand(commandName string, hidden bool, mount MountFn) *cobra.Comm
|
||||
}
|
||||
|
||||
mnt := NewMountPoint(mount, args[1], cmd.NewFsDir(args), &Opt, &vfsflags.Opt)
|
||||
daemon, err := mnt.Mount()
|
||||
mountDaemon, err := mnt.Mount()
|
||||
|
||||
// Wait for foreground mount, if any...
|
||||
if daemon == nil {
|
||||
if mountDaemon == nil {
|
||||
if err == nil {
|
||||
err = mnt.Wait()
|
||||
}
|
||||
@@ -235,15 +235,15 @@ func NewMountCommand(commandName string, hidden bool, mount MountFn) *cobra.Comm
|
||||
return
|
||||
}
|
||||
|
||||
// Wait for daemon, if any...
|
||||
// Wait for mountDaemon, if any...
|
||||
killOnce := sync.Once{}
|
||||
killDaemon := func(reason string) {
|
||||
killOnce.Do(func() {
|
||||
if err := daemon.Signal(os.Interrupt); err != nil {
|
||||
fs.Errorf(nil, "%s. Failed to terminate daemon pid %d: %v", reason, daemon.Pid, err)
|
||||
if err := mountDaemon.Signal(os.Interrupt); err != nil {
|
||||
fs.Errorf(nil, "%s. Failed to terminate daemon pid %d: %v", reason, mountDaemon.Pid, err)
|
||||
return
|
||||
}
|
||||
fs.Debugf(nil, "%s. Terminating daemon pid %d", reason, daemon.Pid)
|
||||
fs.Debugf(nil, "%s. Terminating daemon pid %d", reason, mountDaemon.Pid)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ func NewMountCommand(commandName string, hidden bool, mount MountFn) *cobra.Comm
|
||||
handle := atexit.Register(func() {
|
||||
killDaemon("Got interrupt")
|
||||
})
|
||||
err = WaitMountReady(mnt.MountPoint, Opt.DaemonWait, daemon)
|
||||
err = WaitMountReady(mnt.MountPoint, Opt.DaemonWait, mountDaemon)
|
||||
if err != nil {
|
||||
killDaemon("Daemon timed out")
|
||||
}
|
||||
@@ -275,7 +275,7 @@ func NewMountCommand(commandName string, hidden bool, mount MountFn) *cobra.Comm
|
||||
}
|
||||
|
||||
// Mount the remote at mountpoint
|
||||
func (m *MountPoint) Mount() (daemon *os.Process, err error) {
|
||||
func (m *MountPoint) Mount() (mountDaemon *os.Process, err error) {
|
||||
|
||||
// Ensure sensible defaults
|
||||
m.SetVolumeName(m.MountOpt.VolumeName)
|
||||
@@ -283,9 +283,9 @@ func (m *MountPoint) Mount() (daemon *os.Process, err error) {
|
||||
|
||||
// Start background task if --daemon is specified
|
||||
if m.MountOpt.Daemon {
|
||||
daemon, err = daemonize.StartDaemon(os.Args)
|
||||
if daemon != nil || err != nil {
|
||||
return daemon, err
|
||||
mountDaemon, err = daemonize.StartDaemon(os.Args)
|
||||
if mountDaemon != nil || err != nil {
|
||||
return mountDaemon, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ func (m *MountPoint) Wait() error {
|
||||
var finaliseOnce sync.Once
|
||||
finalise := func() {
|
||||
finaliseOnce.Do(func() {
|
||||
_ = sysdnotify.Stopping()
|
||||
_, _ = daemon.SdNotify(false, daemon.SdNotifyStopping)
|
||||
// Unmount only if directory was mounted by rclone, e.g. don't unmount autofs hooks.
|
||||
if err := CheckMountReady(m.MountPoint); err != nil {
|
||||
fs.Debugf(m.MountPoint, "Unmounted externally. Just exit now.")
|
||||
@@ -322,7 +322,7 @@ func (m *MountPoint) Wait() error {
|
||||
defer atexit.Unregister(fnHandle)
|
||||
|
||||
// Notify systemd
|
||||
if err := sysdnotify.Ready(); err != nil {
|
||||
if _, err := daemon.SdNotify(false, daemon.SdNotifyReady); err != nil {
|
||||
return fmt.Errorf("failed to notify systemd: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user