Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

rcd: Added systemd notification during the 'rclone rcd' command call. This also fixes #5073.

Naveen Honest Raj02a5d350f932
diff --git a/cmd/rcd/rcd.go b/cmd/rcd/rcd.go
index c12efd9e9..cc4be57f9 100644
--- a/cmd/rcd/rcd.go
+++ b/cmd/rcd/rcd.go
@@ -3,10 +3,13 @@ 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"
"github.com/spf13/cobra"
)
@@ -48,6 +51,22 @@ See the [rc documentation](/rc/) for more info on the rc flags.
log.Fatal("rc server not configured")
}
+ // 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)
+ }
+
s.Wait()
+ finalise()
},
}