Signed-off-by: Michael Crosby <michael@docker.com>
| ... | ... |
@@ -501,8 +501,15 @@ func (container *Container) monitor(callback execdriver.StartCallback) error {
|
| 501 | 501 |
err error |
| 502 | 502 |
exitCode int |
| 503 | 503 |
failCount int |
| 504 |
+ |
|
| 505 |
+ policy = container.hostConfig.RestartPolicy |
|
| 504 | 506 |
) |
| 505 | 507 |
|
| 508 |
+ if err := container.startLoggingToDisk(); err != nil {
|
|
| 509 |
+ // TODO: crosbymichael cleanup IO, network, and mounts |
|
| 510 |
+ return err |
|
| 511 |
+ } |
|
| 512 |
+ |
|
| 506 | 513 |
// reset the restart count |
| 507 | 514 |
container.RestartCount = -1 |
| 508 | 515 |
container.requestedStop = false |
| ... | ... |
@@ -511,15 +518,12 @@ func (container *Container) monitor(callback execdriver.StartCallback) error {
|
| 511 | 511 |
container.RestartCount++ |
| 512 | 512 |
|
| 513 | 513 |
pipes := execdriver.NewPipes(container.stdin, container.stdout, container.stderr, container.Config.OpenStdin) |
| 514 |
- if err := container.startLoggingToDisk(); err != nil {
|
|
| 515 |
- return err |
|
| 516 |
- } |
|
| 517 | 514 |
|
| 518 | 515 |
if exitCode, err = container.daemon.Run(container, pipes, callback); err != nil {
|
| 519 | 516 |
failCount++ |
| 520 | 517 |
|
| 521 | 518 |
if failCount == 100 {
|
| 522 |
- return err |
|
| 519 |
+ container.requestedStop = true |
|
| 523 | 520 |
} |
| 524 | 521 |
|
| 525 | 522 |
utils.Errorf("Error running container: %s", err)
|
| ... | ... |
@@ -557,27 +561,27 @@ func (container *Container) monitor(callback execdriver.StartCallback) error {
|
| 557 | 557 |
container.daemon.srv.LogEvent("die", container.ID, container.daemon.repositories.ImageName(container.Image))
|
| 558 | 558 |
} |
| 559 | 559 |
|
| 560 |
- policy := container.hostConfig.RestartPolicy |
|
| 561 |
- |
|
| 562 | 560 |
if (policy == "always" || (policy == "on-failure" && exitCode != 0)) && !container.requestedStop {
|
| 563 | 561 |
container.command.Cmd = copyCmd(&container.command.Cmd) |
| 562 |
+ |
|
| 564 | 563 |
time.Sleep(1 * time.Second) |
| 565 |
- } else {
|
|
| 566 |
- // do not restart the container, let it die |
|
| 567 |
- // Cleanup networking and mounts |
|
| 568 |
- container.cleanup() |
|
| 569 | 564 |
|
| 570 |
- if container.daemon != nil && container.daemon.srv != nil && container.daemon.srv.IsRunning() {
|
|
| 571 |
- // FIXME: here is race condition between two RUN instructions in Dockerfile |
|
| 572 |
- // because they share same runconfig and change image. Must be fixed |
|
| 573 |
- // in builder/builder.go |
|
| 574 |
- if err := container.toDisk(); err != nil {
|
|
| 575 |
- utils.Errorf("Error dumping container %s state to disk: %s\n", container.ID, err)
|
|
| 576 |
- } |
|
| 577 |
- } |
|
| 565 |
+ continue |
|
| 566 |
+ } |
|
| 578 | 567 |
|
| 579 |
- return err |
|
| 568 |
+ // Cleanup networking and mounts |
|
| 569 |
+ container.cleanup() |
|
| 570 |
+ |
|
| 571 |
+ if container.daemon != nil && container.daemon.srv != nil && container.daemon.srv.IsRunning() {
|
|
| 572 |
+ // FIXME: here is race condition between two RUN instructions in Dockerfile |
|
| 573 |
+ // because they share same runconfig and change image. Must be fixed |
|
| 574 |
+ // in builder/builder.go |
|
| 575 |
+ if err := container.toDisk(); err != nil {
|
|
| 576 |
+ utils.Errorf("Error dumping container %s state to disk: %s\n", container.ID, err)
|
|
| 577 |
+ } |
|
| 580 | 578 |
} |
| 579 |
+ |
|
| 580 |
+ return err |
|
| 581 | 581 |
} |
| 582 | 582 |
} |
| 583 | 583 |
|