Add health command for hub and align agent health command

This commit is contained in:
henrygd
2025-03-15 00:23:12 -04:00
parent cadc09b493
commit c38d04b34b
4 changed files with 65 additions and 25 deletions

View File

@@ -6,14 +6,13 @@ import (
)
// 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) {
func Health(addr string, network string) error {
conn, err := net.DialTimeout(network, addr, 4*time.Second)
if err != nil {
return 1, err
return err
}
conn.Close()
return 0, nil
return nil
}