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:
Anagh Kumar Baranwal
2023-11-29 14:55:30 +05:30
committed by Nick Craig-Wood
parent f0c774156e
commit 298c13e719
10 changed files with 72 additions and 55 deletions

View File

@@ -1,10 +1,11 @@
package systemd
import (
"fmt"
"log"
"sync"
sysdnotify "github.com/iguanesolutions/go-systemd/v5/notify"
"github.com/coreos/go-systemd/v22/daemon"
"github.com/rclone/rclone/lib/atexit"
)
@@ -13,13 +14,13 @@ import (
// stopping. This function will be called on exit if the service exits
// on a signal.
func Notify() func() {
if err := sysdnotify.Ready(); err != nil {
if _, err := daemon.SdNotify(false, daemon.SdNotifyReady); err != nil {
log.Printf("failed to notify ready to systemd: %v", err)
}
var finaliseOnce sync.Once
finalise := func() {
finaliseOnce.Do(func() {
if err := sysdnotify.Stopping(); err != nil {
if _, err := daemon.SdNotify(false, daemon.SdNotifyStopping); err != nil {
log.Printf("failed to notify stopping to systemd: %v", err)
}
})
@@ -30,3 +31,10 @@ func Notify() func() {
finalise()
}
}
// UpdateStatus updates the systemd status
func UpdateStatus(status string) error {
systemdStatus := fmt.Sprintf("STATUS=%s", status)
_, err := daemon.SdNotify(false, systemdStatus)
return err
}