Skip to content

Commit

Permalink
inspect container beforce control it
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Jul 2, 2019
1 parent 67022da commit ef26af2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cluster/calcium/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ func (c *Calcium) ControlContainer(ctx context.Context, IDs []string, t string,
message, err = c.doStartContainer(ctx, container, containerInfo, force)
return
case cluster.ContainerRestart:
message, err = c.doStopContainer(ctx, container, containerInfo, force)
if err != nil {
return
if containerInfo, err := container.Inspect(ctx); err == nil && containerInfo.Running {
message, err = c.doStopContainer(ctx, container, containerInfo, force)
if err != nil {
return
}

} else if err != nil {
log.Errorf("[ControlContainer] Inspect container %s failed %v", container.ID, err)
} else if !containerInfo.Running {
message = append(message, bytes.NewBufferString("container stopped, can't run hook\n"))
}
m2, e2 := c.doStartContainer(ctx, container, containerInfo, force)
message = append(message, m2...)
Expand Down

0 comments on commit ef26af2

Please sign in to comment.