-
Notifications
You must be signed in to change notification settings - Fork 111
/
health-check.go
49 lines (40 loc) · 1.03 KB
/
health-check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright © 2017 Chef Software
package main
import (
"fmt"
"os"
"time"
"github.com/spf13/cobra"
"github.com/chef/automate/components/automate-deployment/pkg/client"
)
func init() {
RootCmd.AddCommand(healthCheckCmd())
}
func healthCheckCmd() *cobra.Command {
return &cobra.Command{
Use: "health-check",
Short: "checks server health",
Long: `checks server health.
Environment:
DEPLOYMENT_SERVICE_ADDRESS set to a string like localhost:10160 to
configure the host and port
`,
Run: runHealthCheck,
}
}
func runHealthCheck(cmd *cobra.Command, args []string) {
_, err := client.Connection(1 * time.Second)
if err != nil {
fmt.Printf("FAIL: %s\n", err.Error())
// hab's health checks use the following exit codes:
// * 0: ok
// * 1: warning
// * 2: critical
// * 3: unknown
// * any other code: failed health check with additional output taken from
// health_check stdout.
// we'll prefer 4 to 2 since that includes more debug information.
os.Exit(4)
}
os.Exit(0)
}