mirror of https://github.com/docker/docs.git
Fix truncated plugin binary logs
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
parent
34f6e20165
commit
232c0ea37e
|
@ -79,6 +79,7 @@ type Plugin struct {
|
||||||
type Executor struct {
|
type Executor struct {
|
||||||
pluginStdout, pluginStderr io.ReadCloser
|
pluginStdout, pluginStderr io.ReadCloser
|
||||||
DriverName string
|
DriverName string
|
||||||
|
cmd *exec.Cmd
|
||||||
binaryPath string
|
binaryPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,14 +125,14 @@ func (lbe *Executor) Start() (*bufio.Scanner, *bufio.Scanner, error) {
|
||||||
|
|
||||||
log.Debugf("Launching plugin server for driver %s", lbe.DriverName)
|
log.Debugf("Launching plugin server for driver %s", lbe.DriverName)
|
||||||
|
|
||||||
cmd := exec.Command(lbe.binaryPath)
|
lbe.cmd = exec.Command(lbe.binaryPath)
|
||||||
|
|
||||||
lbe.pluginStdout, err = cmd.StdoutPipe()
|
lbe.pluginStdout, err = lbe.cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("Error getting cmd stdout pipe: %s", err)
|
return nil, nil, fmt.Errorf("Error getting cmd stdout pipe: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
lbe.pluginStderr, err = cmd.StderrPipe()
|
lbe.pluginStderr, err = lbe.cmd.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("Error getting cmd stderr pipe: %s", err)
|
return nil, nil, fmt.Errorf("Error getting cmd stderr pipe: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -142,7 +143,7 @@ func (lbe *Executor) Start() (*bufio.Scanner, *bufio.Scanner, error) {
|
||||||
os.Setenv(PluginEnvKey, PluginEnvVal)
|
os.Setenv(PluginEnvKey, PluginEnvVal)
|
||||||
os.Setenv(PluginEnvDriverName, lbe.DriverName)
|
os.Setenv(PluginEnvDriverName, lbe.DriverName)
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
if err := lbe.cmd.Start(); err != nil {
|
||||||
return nil, nil, fmt.Errorf("Error starting plugin binary: %s", err)
|
return nil, nil, fmt.Errorf("Error starting plugin binary: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,34 +151,34 @@ func (lbe *Executor) Start() (*bufio.Scanner, *bufio.Scanner, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lbe *Executor) Close() error {
|
func (lbe *Executor) Close() error {
|
||||||
|
if err := lbe.cmd.Wait(); err != nil {
|
||||||
|
return fmt.Errorf("Error waiting for binary close: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := lbe.pluginStdout.Close(); err != nil {
|
if err := lbe.pluginStdout.Close(); err != nil {
|
||||||
return err
|
return fmt.Errorf("Error closing plugin stdout: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := lbe.pluginStderr.Close(); err != nil {
|
if err := lbe.pluginStderr.Close(); err != nil {
|
||||||
return err
|
return fmt.Errorf("Error closing plugin stderr: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func stream(scanner *bufio.Scanner, streamOutCh chan<- string, stopCh <-chan bool) {
|
func stream(scanner *bufio.Scanner, streamOutCh chan<- string, stopCh <-chan bool) {
|
||||||
lines := make(chan string)
|
|
||||||
go func() {
|
|
||||||
for scanner.Scan() {
|
|
||||||
lines <- scanner.Text()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-stopCh:
|
case <-stopCh:
|
||||||
close(streamOutCh)
|
close(streamOutCh)
|
||||||
return
|
return
|
||||||
case line := <-lines:
|
default:
|
||||||
streamOutCh <- strings.Trim(line, "\n")
|
scanner.Scan()
|
||||||
|
line := scanner.Text()
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
log.Warnf("Scanning stream: %s", err)
|
log.Warnf("Scanning stream: %s", err)
|
||||||
}
|
}
|
||||||
|
streamOutCh <- strings.Trim(line, "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ Please use this plugin through the main 'docker-machine' binary.
|
||||||
}
|
}
|
||||||
|
|
||||||
log.SetDebug(true)
|
log.SetDebug(true)
|
||||||
|
os.Setenv("MACHINE_DEBUG", "1")
|
||||||
|
|
||||||
rpcd := rpcdriver.NewRPCServerDriver(d)
|
rpcd := rpcdriver.NewRPCServerDriver(d)
|
||||||
rpc.RegisterName(rpcdriver.RPCServiceNameV0, rpcd)
|
rpc.RegisterName(rpcdriver.RPCServiceNameV0, rpcd)
|
||||||
|
@ -50,10 +51,12 @@ Please use this plugin through the main 'docker-machine' binary.
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-rpcd.CloseCh:
|
case <-rpcd.CloseCh:
|
||||||
|
log.Debug("Closing plugin on server side")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
case <-rpcd.HeartbeatCh:
|
case <-rpcd.HeartbeatCh:
|
||||||
continue
|
continue
|
||||||
case <-time.After(heartbeatTimeout):
|
case <-time.After(heartbeatTimeout):
|
||||||
|
// TODO: Add heartbeat retry logic
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,12 +189,6 @@ func (c *RPCClientDriver) close() error {
|
||||||
c.heartbeatDoneCh <- true
|
c.heartbeatDoneCh <- true
|
||||||
close(c.heartbeatDoneCh)
|
close(c.heartbeatDoneCh)
|
||||||
|
|
||||||
log.Debug("Making call to close connection to plugin binary")
|
|
||||||
|
|
||||||
if err := c.plugin.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debug("Making call to close driver server")
|
log.Debug("Making call to close driver server")
|
||||||
|
|
||||||
if err := c.Client.Call(CloseMethod, struct{}{}, nil); err != nil {
|
if err := c.Client.Call(CloseMethod, struct{}{}, nil); err != nil {
|
||||||
|
@ -203,6 +197,12 @@ func (c *RPCClientDriver) close() error {
|
||||||
|
|
||||||
log.Debug("Successfully made call to close driver server")
|
log.Debug("Successfully made call to close driver server")
|
||||||
|
|
||||||
|
log.Debug("Making call to close connection to plugin binary")
|
||||||
|
|
||||||
|
if err := c.plugin.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue