-
Notifications
You must be signed in to change notification settings - Fork 0
/
wait.go
31 lines (24 loc) · 924 Bytes
/
wait.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
package main
import (
"os"
"time"
"github.com/alecthomas/kong"
"github.com/taisph/probe/pkg/addrprobe"
)
type waitCmdCli struct {
Wait waitCmd `cmd help:"Wait for hosts"`
}
type waitCmd struct {
Timeout int `name:"timeout" help:"Give up after this many seconds." default:"30"`
Delay int `name:"delay" help:"Delay in seconds between connection attempts." default:"5"`
NetAddresses []string `arg name:"net-address" help:"Comma separated list of network addresses to probe in the format host:port, tcp:host:port or unix:/path/to/socket."`
}
// Run the command
func (cmd *waitCmd) Run(ctx *kong.Context, cfg appCfg) error {
p := addrprobe.New(addrprobe.Config{Log: cfg.log, Quit: cfg.quit, Delay: time.Duration(cmd.Delay) * time.Second})
if !p.Run(cmd.NetAddresses, time.Duration(cmd.Timeout)*time.Second) {
cfg.log.Error().Msg("One or more probes failed")
os.Exit(1)
}
return nil
}