How use Stop method?

i found start filebeat "cmd.RootCmd.Execute()" method,but i don't know stop method.
no Stop api in the simple cmd interface,i don't hope stoped by "ctrl+c/d". the filebeat as module to my app. i hope i call “cmd.RootCmd.Stop()”:smiley:

What is your use case? Do you want to start a Filebeat instance from Golang code?

1 Like

yes,but i found cmd.RootCmd.Execute and no Stop method."crtl c/d" is not good way,it killall.

example code in project:
start:
go func(){
//start filebeat instance
cmd.RootCmd.Execute()
}
//if filebeat.yam updated,stop filebeat instance and start.
go func(){
//stop method
//start method
cmd.RootCmd.Execute()
}

stop method is exist in filebeat code.but it was no obvious exposure. i don't know use it.

What is your use case? What do you want to automate with your code? Do you need to reload configuration if one of the files changed? Have you looked at this documentation? https://www.elastic.co/guide/en/beats/filebeat/current/_live_reloading.html

Filebeat is not intended to be used this way. If you really need to start and stop Filebeat from Golang I suggest you the exec package to start and stop: https://golang.org/pkg/os/exec/

Examples:
Starting Filebeat

cmd := exec.Command("./filebeat")
err := cmd.Start()
if err != nil {
    log.Errorf("Error while running Filebeat: %+v", err)
}

Stopping Filebeat

cmd.Process.Kill()

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.