Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4232 from andrestc/apt-retry
Browse files Browse the repository at this point in the history
libmachine/provision: retries pkg installation if fails to get lock
  • Loading branch information
dgageot authored Feb 12, 2018
2 parents 2f0ad26 + bda4f00 commit e0e4da5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
6 changes: 1 addition & 5 deletions libmachine/provision/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ func (provisioner *DebianProvisioner) Package(name string, action pkgaction.Pack

log.Debugf("package: action=%s name=%s", action.String(), name)

if _, err := provisioner.SSHCommand(command); err != nil {
return err
}

return nil
return waitForLock(provisioner, command)
}

func (provisioner *DebianProvisioner) dockerDaemonResponding() bool {
Expand Down
6 changes: 1 addition & 5 deletions libmachine/provision/ubuntu_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ func (provisioner *UbuntuSystemdProvisioner) Package(name string, action pkgacti

log.Debugf("package: action=%s name=%s", action.String(), name)

if _, err := provisioner.SSHCommand(command); err != nil {
return err
}

return nil
return waitForLock(provisioner, command)
}

func (provisioner *UbuntuSystemdProvisioner) dockerDaemonResponding() bool {
Expand Down
6 changes: 1 addition & 5 deletions libmachine/provision/ubuntu_upstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ func (provisioner *UbuntuProvisioner) Package(name string, action pkgaction.Pack

log.Debugf("package: action=%s name=%s", action.String(), name)

if _, err := provisioner.SSHCommand(command); err != nil {
return err
}

return nil
return waitForLock(provisioner, command)
}

func (provisioner *UbuntuProvisioner) dockerDaemonResponding() bool {
Expand Down
10 changes: 7 additions & 3 deletions libmachine/provision/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,13 @@ func DockerClientVersion(ssh SSHCommander) (string, error) {
}

func waitForLockAptGetUpdate(ssh SSHCommander) error {
return waitForLock(ssh, "sudo apt-get update")
}

func waitForLock(ssh SSHCommander, cmd string) error {
var sshErr error
err := mcnutils.WaitFor(func() bool {
_, sshErr = ssh.SSHCommand("sudo apt-get update")
_, sshErr = ssh.SSHCommand(cmd)
if sshErr != nil {
if strings.Contains(sshErr.Error(), "Could not get lock") {
sshErr = nil
Expand All @@ -309,10 +313,10 @@ func waitForLockAptGetUpdate(ssh SSHCommander) error {
return true
})
if sshErr != nil {
return fmt.Errorf("Error running apt-get update: %s", sshErr)
return fmt.Errorf("Error running %q: %s", cmd, sshErr)
}
if err != nil {
return fmt.Errorf("Failed to obtain apt-get update lock: %s", err)
return fmt.Errorf("Failed to obtain lock: %s", err)
}
return nil
}

0 comments on commit e0e4da5

Please sign in to comment.