Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systemd returns error on inactive, so allow that #4095

Merged
merged 1 commit into from
Apr 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions cmd/minikube/cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (
"text/template"

"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/host"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/shell"
"github.com/docker/machine/libmachine/state"
"github.com/pkg/errors"
Expand Down Expand Up @@ -301,13 +303,31 @@ func (EnvNoProxyGetter) GetNoProxyVar() (string, string) {
return noProxyVar, noProxyValue
}

// same as drivers.RunSSHCommandFromDriver, but allows errors
func runSSHCommandFromDriver(d drivers.Driver, command string) (string, error) {
client, err := drivers.GetSSHClientFromDriver(d)
if err != nil {
return "", err
}

log.Debugf("About to run SSH command:\n%s", command)
output, err := client.Output(command)
log.Debugf("SSH cmd err, output: %v: %s", err, output)
return output, err
}

// same as host.RunSSHCommand, but allows errors
func runSSHCommand(h *host.Host, command string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a one-line function to call another new function seems weird. Can they be combined?

return runSSHCommandFromDriver(h.Driver, command)
}

// GetDockerActive checks if Docker is active
func GetDockerActive(host *host.Host) (bool, error) {
statusCmd := `sudo systemctl is-active docker`
status, err := host.RunSSHCommand(statusCmd)
status, err := runSSHCommand(host, statusCmd)
// systemd returns error code on inactive
s := strings.TrimSpace(status)
return err == nil && s == "active", err
return err == nil && s == "active", nil
}

// envCmd represents the docker-env command
Expand Down