Commit 5cb2c77c authored by Lei Li's avatar Lei Li
Browse files

fix: 修复守护进程无法转发信号的问题

parent c9ec1358
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"syscall"
"time" "time"
"agent/cmd/agent/config" "agent/cmd/agent/config"
...@@ -24,6 +23,8 @@ import ( ...@@ -24,6 +23,8 @@ import (
var AgentSvc = &Agent{} var AgentSvc = &Agent{}
var monitorDaemon *monitor_daemon.MonitorDaemon
type Agent struct { type Agent struct {
IsStop bool IsStop bool
} }
...@@ -84,14 +85,15 @@ func (a *Agent) Start() error { ...@@ -84,14 +85,15 @@ func (a *Agent) Start() error {
opts = append(opts, monitor_daemon.WithIsProcAbnormalCallback(IsProcAbnormal)) opts = append(opts, monitor_daemon.WithIsProcAbnormalCallback(IsProcAbnormal))
} }
monitorDaemon, err := monitor_daemon.New(cmdline, opts...) var err error
monitorDaemon, err = monitor_daemon.New(cmdline, opts...)
if err != nil { if err != nil {
l.Error("monitor_daemon new error:", err, ", cmdline:", cmdline) l.Errorf("cmdline:%s, monitor_daemon new err:%s", cmdline, err)
os.Exit(1) os.Exit(1)
} }
go func() { go func() {
l.Info("monitor_daemon run, cmdline:", cmdline) l.Info("monitor_daemon run, cmdline:", cmdline)
monitorDaemon.Run(syscall.SIGTERM, syscall.SIGINT) monitorDaemon.Run()
l.Info("======monitor_daemon stop======") l.Info("======monitor_daemon stop======")
}() }()
return nil return nil
...@@ -116,12 +118,14 @@ func (a *Agent) Stop() error { ...@@ -116,12 +118,14 @@ func (a *Agent) Stop() error {
// monitor进程直接退出 // monitor进程直接退出
if option.Opt.EnableMonitorDaemon { if option.Opt.EnableMonitorDaemon {
if monitorDaemon != nil {
monitorDaemon.KillProcess()
}
l.Info("agent daemon stopped") l.Info("agent daemon stopped")
return nil return nil
} }
l.Info("agent stop")
module.StopEveryModule() module.StopEveryModule()
l.Info("agent stopped")
} }
return nil return nil
} }
......
...@@ -2,20 +2,17 @@ package main ...@@ -2,20 +2,17 @@ package main
import ( import (
"agent/cmd/agent/core" "agent/cmd/agent/core"
"os"
"syscall"
"github.com/judwhite/go-svc" "github.com/judwhite/go-svc"
"os"
"linkfog.com/public/lib/l" "linkfog.com/public/lib/l"
) )
func main() { func main() {
if err := svc.Run(core.AgentSvc, syscall.SIGINT, syscall.SIGTERM); err != nil { if err := svc.Run(core.AgentSvc); err != nil {
l.Errorf("agent svc run err:%v, program exit", err) l.Errorf("agent svc run err:%v, program exit", err)
l.Close() l.Close()
os.Exit(1) os.Exit(1)
} }
l.Info("agent svc run finished, program exit")
l.Close() l.Close()
} }
...@@ -2,7 +2,7 @@ module agent ...@@ -2,7 +2,7 @@ module agent
go 1.23.2 go 1.23.2
replace linkfog.com/public => web.lueluesay.top/git/lil/public v0.0.0-20241015034013-544ad0ec734d replace linkfog.com/public => web.lueluesay.top/git/lil/public v0.0.0-20241017054747-f08bac907b6c
replace linkfog.com/pluginx => web.lueluesay.top/git/lil/pluginx v0.0.0-20241017031415-3651ccc20390 replace linkfog.com/pluginx => web.lueluesay.top/git/lil/pluginx v0.0.0-20241017031415-3651ccc20390
......
...@@ -60,5 +60,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= ...@@ -60,5 +60,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
web.lueluesay.top/git/lil/pluginx v0.0.0-20241017031415-3651ccc20390 h1:V3uBqmiRc4xlBWfHRDETMGHTvLF+3mOGIZH/E46XcNI= web.lueluesay.top/git/lil/pluginx v0.0.0-20241017031415-3651ccc20390 h1:V3uBqmiRc4xlBWfHRDETMGHTvLF+3mOGIZH/E46XcNI=
web.lueluesay.top/git/lil/pluginx v0.0.0-20241017031415-3651ccc20390/go.mod h1:DL73qsfCIFfH2K6tdOLPj9tRcZ8AYxfPrkcTebYXr5o= web.lueluesay.top/git/lil/pluginx v0.0.0-20241017031415-3651ccc20390/go.mod h1:DL73qsfCIFfH2K6tdOLPj9tRcZ8AYxfPrkcTebYXr5o=
web.lueluesay.top/git/lil/public v0.0.0-20241015034013-544ad0ec734d h1:vScdJPO4B87cVCZU26EddFpdQTDxTocD2RSLcoHwy5k= web.lueluesay.top/git/lil/public v0.0.0-20241017054747-f08bac907b6c h1:U/2ffmB20mPiC1GT0eTrc9GAQDCd2a8W4zAIb8wf1ds=
web.lueluesay.top/git/lil/public v0.0.0-20241015034013-544ad0ec734d/go.mod h1:x/nRP9pMRVToI9Te1TazybP0Qlj3V+/aA2EiPQEvzsI= web.lueluesay.top/git/lil/public v0.0.0-20241017054747-f08bac907b6c/go.mod h1:x/nRP9pMRVToI9Te1TazybP0Qlj3V+/aA2EiPQEvzsI=
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment