-
Notifications
You must be signed in to change notification settings - Fork 111
/
serve.go
35 lines (29 loc) · 899 Bytes
/
serve.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
package commands
import (
"github.com/chef/automate/components/automate-ha-pgleaderchk/pkg/pgleaderchk"
_ "github.com/lib/pq"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Launches the webserver and checks local PostgreSQL for leader status",
Run: func(cmd *cobra.Command, args []string) {
log.Info("Starting Chef Automate Backend PostgreSQL Leader Check Service")
cfg, err := pgleaderchk.ConfigFromViper()
if err != nil {
log.WithError(err).Fatal("Failed to configure service")
}
server, err := pgleaderchk.NewFromConfig(cfg)
if err != nil {
log.WithError(err).Fatal("Failed to configure service")
}
// if Serve returns, something went wrong
if err := server.Serve(); err != nil {
log.WithError(err).Fatal("Failed to start service")
}
},
}
func init() {
RootCmd.AddCommand(serveCmd)
}