mirror of
https://github.com/henrygd/beszel.git
synced 2025-12-17 10:46:16 +01:00
add health check for agent
- Updated command-line flag parsing. - Moved GetAddress and GetNetwork to server.go
This commit is contained in:
19
beszel/internal/agent/health.go
Normal file
19
beszel/internal/agent/health.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Health checks if the agent's server is running by attempting to connect to it.
|
||||
// It returns 0 if the server is running, 1 otherwise (as in exit codes).
|
||||
//
|
||||
// If an error occurs when attempting to connect to the server, it returns the error.
|
||||
func Health(addr string, network string) (int, error) {
|
||||
conn, err := net.DialTimeout(network, addr, 4*time.Second)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
conn.Close()
|
||||
return 0, nil
|
||||
}
|
||||
Reference in New Issue
Block a user