-
Notifications
You must be signed in to change notification settings - Fork 0
/
nest.go
63 lines (56 loc) · 1.13 KB
/
nest.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
54
55
56
57
58
59
60
61
62
63
package robin
import (
"fmt"
"io"
"os/exec"
"time"
"github.com/rs/zerolog/log"
"github.com/unkaktus/robin/nest"
)
const (
maxRetries int = 5
retryDelay time.Duration = 1 * time.Second
)
func Nest(bs BatchSystem, cmdline []string, noCommand, verbose bool) error {
NestVariables := bs.NestVariables()
nodeHead := make(chan struct{})
go func() {
var err error
for retry := 0; retry < maxRetries; retry++ {
if err = nest.RunShellServer(nodeHead); err != nil {
time.Sleep(retryDelay)
continue
}
break
}
if err != nil {
if verbose {
log.Err(err).Msg("robin: could not start shell server")
}
}
}()
go func() {
<-nodeHead
cmd := exec.Command("node_exporter")
cmd.Stdout = io.Discard
cmd.Stderr = io.Discard
if err := cmd.Run(); err != nil {
if verbose {
log.Err(err).Msg("run node head")
}
}
}()
if noCommand {
select {}
} else {
process, err := nest.RunCommand(cmdline, NestVariables)
if err != nil {
return fmt.Errorf("running command: %w", err)
}
err = process.Wait()
if err != nil {
return fmt.Errorf("nested process: %w", err)
}
}
return nil
}