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

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

parent c9ec1358
......@@ -5,7 +5,6 @@ import (
"os"
"path/filepath"
"strings"
"syscall"
"time"
"agent/cmd/agent/config"
......@@ -24,6 +23,8 @@ import (
var AgentSvc = &Agent{}
var monitorDaemon *monitor_daemon.MonitorDaemon
type Agent struct {
IsStop bool
}
......@@ -84,14 +85,15 @@ func (a *Agent) Start() error {
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 {
l.Error("monitor_daemon new error:", err, ", cmdline:", cmdline)
l.Errorf("cmdline:%s, monitor_daemon new err:%s", cmdline, err)
os.Exit(1)
}
go func() {
l.Info("monitor_daemon run, cmdline:", cmdline)
monitorDaemon.Run(syscall.SIGTERM, syscall.SIGINT)
monitorDaemon.Run()
l.Info("======monitor_daemon stop======")
}()
return nil
......@@ -116,12 +118,14 @@ func (a *Agent) Stop() error {
// monitor进程直接退出
if option.Opt.EnableMonitorDaemon {
if monitorDaemon != nil {
monitorDaemon.KillProcess()
}
l.Info("agent daemon stopped")
return nil
}
l.Info("agent stop")
module.StopEveryModule()
l.Info("agent stopped")
}
return nil
}
......
......@@ -2,20 +2,17 @@ package main
import (
"agent/cmd/agent/core"
"os"
"syscall"
"github.com/judwhite/go-svc"
"os"
"linkfog.com/public/lib/l"
)
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.Close()
os.Exit(1)
}
l.Info("agent svc run finished, program exit")
l.Close()
}
......@@ -2,7 +2,7 @@ module agent
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
......
......@@ -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=
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/public v0.0.0-20241015034013-544ad0ec734d h1:vScdJPO4B87cVCZU26EddFpdQTDxTocD2RSLcoHwy5k=
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 h1:U/2ffmB20mPiC1GT0eTrc9GAQDCd2a8W4zAIb8wf1ds=
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