mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-04-23 03:00:50 -04:00
Revert "fix(docker redis): Fix redis docker randomly panic. (#267)"
This reverts commit c8c063b622.
This commit is contained in:
@@ -42,35 +42,8 @@ func (r *ImgRedis) Start() error {
|
||||
if id != "" {
|
||||
return fmt.Errorf("container already exist, name: %s", r.name)
|
||||
}
|
||||
// Add check status function.
|
||||
keyword := "Ready to accept connections"
|
||||
okCh := make(chan struct{}, 1)
|
||||
r.cmd.RegistFunc(keyword, func(buf string) {
|
||||
if strings.Contains(buf, keyword) {
|
||||
select {
|
||||
case okCh <- struct{}{}:
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
defer r.cmd.UnRegistFunc(keyword)
|
||||
|
||||
// Start redis.
|
||||
r.cmd.RunCmd(true)
|
||||
|
||||
// Wait result of keyword.
|
||||
select {
|
||||
case <-okCh:
|
||||
utils.TryTimes(3, func() bool {
|
||||
r.id = GetContainerID(r.name)
|
||||
return r.id != ""
|
||||
})
|
||||
case <-time.After(time.Second * 10):
|
||||
}
|
||||
|
||||
// Set redis status.
|
||||
r.running = r.id != ""
|
||||
r.running = r.isOk()
|
||||
if !r.running {
|
||||
_ = r.Stop()
|
||||
return fmt.Errorf("failed to start image: %s", r.image)
|
||||
@@ -118,3 +91,30 @@ func (r *ImgRedis) prepare() []string {
|
||||
}
|
||||
return append(append(cmds, ports...), r.image)
|
||||
}
|
||||
|
||||
func (r *ImgRedis) isOk() bool {
|
||||
keyword := "Ready to accept connections"
|
||||
okCh := make(chan struct{}, 1)
|
||||
r.cmd.RegistFunc(keyword, func(buf string) {
|
||||
if strings.Contains(buf, keyword) {
|
||||
select {
|
||||
case okCh <- struct{}{}:
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
defer r.cmd.UnRegistFunc(keyword)
|
||||
|
||||
// Wait result.
|
||||
select {
|
||||
case <-okCh:
|
||||
utils.TryTimes(3, func() bool {
|
||||
r.id = GetContainerID(r.name)
|
||||
return r.id != ""
|
||||
})
|
||||
return r.id != ""
|
||||
case <-time.After(time.Second * 10):
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,6 @@ func GetContainerID(name string) string {
|
||||
filter := filters.NewArgs()
|
||||
filter.Add("name", name)
|
||||
lst, _ := cli.ContainerList(context.Background(), types.ContainerListOptions{
|
||||
Latest: true,
|
||||
Limit: 1,
|
||||
Filters: filter,
|
||||
})
|
||||
if len(lst) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user