Merge pull request #1247 from ehazlett/redhat-tty-fix

redhat: fix tty provision bug
This commit is contained in:
Evan Hazlett 2015-05-27 13:57:44 -04:00
commit be7c110dfd
2 changed files with 53 additions and 3 deletions

View File

@ -8,15 +8,15 @@ import (
"github.com/docker/machine/utils"
)
func RunSSHCommandFromDriver(d Driver, command string) (string, error) {
func GetSSHClientFromDriver(d Driver) (ssh.Client, error) {
addr, err := d.GetSSHHostname()
if err != nil {
return "", err
return nil, err
}
port, err := d.GetSSHPort()
if err != nil {
return "", err
return nil, err
}
auth := &ssh.Auth{
@ -24,13 +24,21 @@ func RunSSHCommandFromDriver(d Driver, command string) (string, error) {
}
client, err := ssh.NewClient(d.GetSSHUsername(), addr, port, auth)
return client, err
}
func RunSSHCommandFromDriver(d Driver, command string) (string, error) {
client, err := 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
}

View File

@ -11,6 +11,7 @@ import (
"github.com/docker/machine/libmachine/provision/pkgaction"
"github.com/docker/machine/libmachine/swarm"
"github.com/docker/machine/log"
"github.com/docker/machine/ssh"
"github.com/docker/machine/utils"
)
@ -47,6 +48,47 @@ type RedHatProvisioner struct {
DockerRPMPath string
}
func (provisioner *RedHatProvisioner) SSHCommand(args string) (string, error) {
client, err := drivers.GetSSHClientFromDriver(provisioner.Driver)
if err != nil {
return "", err
}
// redhat needs "-t" for tty allocation on ssh therefore we check for the
// external client and add as needed
// TODO: does this need to be done for the native ssh client?
if c, ok := client.(ssh.ExternalClient); ok {
log.Debugf("detected external ssh; added tty allocation flag")
c.BaseArgs = append(c.BaseArgs, "-t")
client = c
}
return client.Output(args)
}
func (provisioner *RedHatProvisioner) SetHostname(hostname string) error {
// we have to have SetHostname here as well to use the RedHat provisioner
// SSHCommand to add the tty allocation
if _, err := provisioner.SSHCommand(fmt.Sprintf(
"sudo hostname %s && echo %q | sudo tee /etc/hostname",
hostname,
hostname,
)); err != nil {
return err
}
// ubuntu/debian use 127.0.1.1 for non "localhost" loopback hostnames: https://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_hostname_resolution
if _, err := provisioner.SSHCommand(fmt.Sprintf(
"if grep -xq 127.0.1.1.* /etc/hosts; then sudo sed -i 's/^127.0.1.1.*/127.0.1.1 %s/g' /etc/hosts; else echo '127.0.1.1 %s' | sudo tee -a /etc/hosts; fi",
hostname,
hostname,
)); err != nil {
return err
}
return nil
}
func (provisioner *RedHatProvisioner) Service(name string, action pkgaction.ServiceAction) error {
reloadDaemon := false
switch action {