cmd: refactor and use sysdnotify in more commands

* cmd: refactor and use sysdnotify in more commands

Fixes #5117
This commit is contained in:
eNV25
2023-09-04 17:32:04 +02:00
committed by GitHub
parent 6afd7088d3
commit ad724463a5
8 changed files with 46 additions and 27 deletions

View File

@@ -4,14 +4,12 @@ package rcd
import (
"context"
"log"
"sync"
sysdnotify "github.com/iguanesolutions/go-systemd/v5/notify"
"github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs/rc/rcflags"
"github.com/rclone/rclone/fs/rc/rcserver"
"github.com/rclone/rclone/lib/atexit"
libhttp "github.com/rclone/rclone/lib/http"
"github.com/rclone/rclone/lib/systemd"
"github.com/spf13/cobra"
)
@@ -58,21 +56,8 @@ See the [rc documentation](/rc/) for more info on the rc flags.
}
// Notify stopping on exit
var finaliseOnce sync.Once
finalise := func() {
finaliseOnce.Do(func() {
_ = sysdnotify.Stopping()
})
}
fnHandle := atexit.Register(finalise)
defer atexit.Unregister(fnHandle)
// Notify ready to systemd
if err := sysdnotify.Ready(); err != nil {
log.Fatalf("failed to notify ready to systemd: %v", err)
}
defer systemd.Notify()()
s.Wait()
finalise()
},
}