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

Signed-off-by: Naveen Honest Raj <naveendurai19@gmail.com>
This commit is contained in:
Naveen Honest Raj 2021-03-02 02:09:33 -08:00 committed by Nick Craig-Wood
parent 18cd2064ec
commit 02a5d350f9

View File

@ -3,10 +3,13 @@ package rcd
import ( import (
"context" "context"
"log" "log"
"sync"
sysdnotify "github.com/iguanesolutions/go-systemd/v5/notify"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs/rc/rcflags" "github.com/rclone/rclone/fs/rc/rcflags"
"github.com/rclone/rclone/fs/rc/rcserver" "github.com/rclone/rclone/fs/rc/rcserver"
"github.com/rclone/rclone/lib/atexit"
"github.com/spf13/cobra" "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") 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() s.Wait()
finalise()
}, },
} }