add signal
This commit is contained in:
parent
c9ad83d0e0
commit
a804d15741
|
@ -2,6 +2,7 @@ package agent
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"path"
|
||||
"strconv"
|
||||
|
||||
|
@ -33,3 +34,17 @@ func NewAgent(configDir, debugMode string) (*Agent, error) {
|
|||
func (a *Agent) String() string {
|
||||
return fmt.Sprintf("<ConfigDir:%s DebugMode:%v>", a.ConfigDir, a.DebugMode)
|
||||
}
|
||||
|
||||
func (a *Agent) Start() {
|
||||
log.Println("I! agent starting")
|
||||
}
|
||||
|
||||
func (a *Agent) Stop() {
|
||||
log.Println("I! agent stopping")
|
||||
|
||||
}
|
||||
|
||||
func (a *Agent) Reload() {
|
||||
log.Println("I! agent reloading")
|
||||
|
||||
}
|
||||
|
|
24
main.go
24
main.go
|
@ -4,6 +4,8 @@ import (
|
|||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"flashcat.cloud/categraf/agent"
|
||||
"flashcat.cloud/categraf/pkg/osx"
|
||||
|
@ -30,7 +32,27 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
log.Println(ag)
|
||||
sc := make(chan os.Signal, 1)
|
||||
signal.Notify(sc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
||||
|
||||
ag.Start()
|
||||
|
||||
EXIT:
|
||||
for {
|
||||
sig := <-sc
|
||||
log.Println("I! received signal:", sig.String())
|
||||
switch sig {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
break EXIT
|
||||
case syscall.SIGHUP:
|
||||
ag.Reload()
|
||||
default:
|
||||
break EXIT
|
||||
}
|
||||
}
|
||||
|
||||
ag.Stop()
|
||||
log.Println("I! exited")
|
||||
}
|
||||
|
||||
func printEnv() {
|
||||
|
|
Loading…
Reference in New Issue