-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.go
More file actions
64 lines (56 loc) · 1.14 KB
/
start.go
File metadata and controls
64 lines (56 loc) · 1.14 KB
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
package bedis
import (
"bufio"
"context"
"fmt"
"os/exec"
"time"
)
func (r *builtinRedis) start(ctx context.Context) error {
cmd := exec.CommandContext(ctx, binPath, r.confPath)
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
logs.Printf("redis starting")
// set cpu affinity
if r.opt.CPUAffinity {
if cpu, err := setCPUAffinity(cmd.Process.Pid); err != nil {
logs.Printf("set cpu affinity err: %s", err)
} else {
defer givebackCPU(cpu)
}
}
go func() {
in := bufio.NewScanner(stdout)
for in.Scan() {
logs.Println(in.Text())
}
}()
go func() {
in := bufio.NewScanner(stderr)
for in.Scan() {
logs.Println(in.Text())
}
}()
return cmd.Wait()
}
func (r *builtinRedis) checkStatus() error {
// check if redis started
for i := 0; i <= 3; i++ {
if !fileExists(r.socketPath) {
logs.Printf("redis socket %s not exist", r.socketPath)
time.Sleep(time.Millisecond * 100 * time.Duration(i+1))
continue
}
return nil
}
return fmt.Errorf("cannot start redis in 3 seconds")
}