-
Notifications
You must be signed in to change notification settings - Fork 73
/
run.go
68 lines (59 loc) · 1.14 KB
/
run.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
64
65
66
67
68
package main
import (
"fmt"
"os"
"os/exec"
"strconv"
"time"
)
var Interval time.Duration //检测时间间隔
func main() {
tmp := os.Getenv("Interval")
Interval = 60 * time.Second
tmp1, err := strconv.ParseInt(tmp, 10, 64)
fmt.Println(tmp1)
if err == nil {
Interval = time.Duration(tmp1) * time.Second
}
cmd := exec.Command("/home/work/uploadCadviosrData/cadvisor")
if err = cmd.Start(); err != nil {
fmt.Println(err)
return
}
fmt.Println("start cadvisor ok", Interval)
go func() {
t := time.NewTicker(Interval)
for {
<-t.C
cmd = exec.Command("/home/work/uploadCadviosrData/uploadCadvisorData")
if err := cmd.Start(); err != nil {
fmt.Println(err)
return
}
cmd.Wait()
}
}()
for {
time.Sleep(time.Second * 120)
if isAlive() {
clean()
} else {
os.Exit(1)
}
}
}
func isAlive() bool {
f, _ := os.OpenFile("test.txt", os.O_CREATE|os.O_APPEND|os.O_RDONLY, 0660)
defer f.Close()
read_buf := make([]byte, 32)
var pos int64 = 0
n, _ := f.ReadAt(read_buf, pos)
if n == 0 {
return false
}
return true
}
func clean() {
f, _ := os.OpenFile("test.txt", os.O_TRUNC, 0660)
defer f.Close()
}