feat(watchdog): add watchdog service with TCP client implementation
- Implement TCP client for watchdog service communication - Add watchdog configuration in config.json - Update main.go to initialize and connect to watchdog - Add watchdog related functions (connect, command handling) - Update README.md with new watchdog feature - Improve route setup logging in router.go
This commit is contained in:
47
watchdog/connect.go
Normal file
47
watchdog/connect.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package watchdog
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func Connect(ipaddr string, port int) bool {
|
||||
if IsConnected() {
|
||||
return true
|
||||
}
|
||||
|
||||
if err := Init(); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if err := tcpConnect(ipaddr, port); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
response, err := sendMsg("watchdogAgentConnectionTest", 3)
|
||||
if err != nil {
|
||||
Destroy()
|
||||
return false
|
||||
}
|
||||
|
||||
if response != "success" {
|
||||
Destroy()
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func Disconnect() bool {
|
||||
if !IsConnected() {
|
||||
return true
|
||||
}
|
||||
|
||||
err := Destroy()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user