-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
53 lines (44 loc) · 1.05 KB
/
main.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
50
51
52
53
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/OpenSlides/openslides-manage-service/pkg/connection"
"github.com/OpenSlides/openslides-manage-service/pkg/server"
"github.com/OpenSlides/openslides-manage-service/proto"
"google.golang.org/grpc/status"
)
const (
timeout = 1 * time.Second
)
func healthcheck() error {
cfg := server.ConfigFromEnv(os.LookupEnv)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
cl, close, err := connection.Dial(
ctx,
"localhost:"+cfg.Port,
cfg.ManageAuthPasswordFile,
false,
)
if err != nil {
return fmt.Errorf("connecting to gRPC server: %w", err)
}
defer close()
resp, err := cl.Health(ctx, &proto.HealthRequest{})
if err != nil {
s, _ := status.FromError(err) // The ok value does not matter here.
return fmt.Errorf("calling manage service: %s", s.Message())
}
if !resp.Healthy {
return fmt.Errorf("manage service is unhealthy")
}
return nil
}
func main() {
if err := healthcheck(); err != nil {
os.Stderr.WriteString(err.Error())
os.Exit(1)
}
}