55 lines
1.5 KiB
Diff
55 lines
1.5 KiB
Diff
From c65a42ea5d2e3626adfd5d09864b2b4bdb0f27d5 Mon Sep 17 00:00:00 2001
|
|
From: Longjun Luo <luolongjuna@gmail.com>
|
|
Date: Mon, 26 Dec 2022 23:53:48 +0800
|
|
Subject: [PATCH] systemd: solve the problem of parsing pid of message
|
|
|
|
When restore the service of Notify, need to parse
|
|
the right pid.
|
|
|
|
Signed-off-by: Longjun Luo <luolongjuna@gmail.com>
|
|
---
|
|
src/client.go | 2 +-
|
|
src/systemd.go | 9 ++++++++-
|
|
2 files changed, 9 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/client.go b/src/client.go
|
|
index 2bf6875..70d5832 100644
|
|
--- a/src/client.go
|
|
+++ b/src/client.go
|
|
@@ -79,7 +79,7 @@ func startClient(path string) {
|
|
if ret != 0 {
|
|
handleRet("restore", ret)
|
|
}
|
|
- RestoreMainPid(c.Args().Get(1))
|
|
+ RestoreMainPid(c.Args().First())
|
|
NotifySytemd()
|
|
SystemdReload()
|
|
return nil
|
|
diff --git a/src/systemd.go b/src/systemd.go
|
|
index 65c53bc..cae7c05 100644
|
|
--- a/src/systemd.go
|
|
+++ b/src/systemd.go
|
|
@@ -1,11 +1,18 @@
|
|
package main
|
|
|
|
import (
|
|
+ "strings"
|
|
"github.com/coreos/go-systemd/daemon"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
-func RestoreMainPid(pid string) {
|
|
+func RestoreMainPid(command string) {
|
|
+ commands := strings.Split(command, "@")
|
|
+ if (len(commands) != 2) {
|
|
+ log.Errorf("Invalid command format %s \n", command)
|
|
+ return
|
|
+ }
|
|
+ pid := commands[1]
|
|
ifSupport, err := daemon.SdNotify(false, "READY=1\nMAINPID="+pid)
|
|
if ifSupport == false || err != nil {
|
|
log.Errorf("Unable to notify systemd, support %v err %s \n", ifSupport, err)
|
|
--
|
|
2.38.1
|
|
|