packer/plugin: client kill waits for logging to complete
This commit is contained in:
parent
e1785e424e
commit
c8079a4290
|
@ -14,12 +14,14 @@ import (
|
||||||
type client struct {
|
type client struct {
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
exited bool
|
exited bool
|
||||||
|
doneLogging bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(cmd *exec.Cmd) *client {
|
func NewClient(cmd *exec.Cmd) *client {
|
||||||
return &client{
|
return &client{
|
||||||
cmd,
|
cmd,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +106,18 @@ func (c *client) Start() (address string, err error) {
|
||||||
|
|
||||||
func (c *client) Kill() {
|
func (c *client) Kill() {
|
||||||
c.cmd.Process.Kill()
|
c.cmd.Process.Kill()
|
||||||
|
|
||||||
|
// Wait for the client to finish logging so we have a complete log
|
||||||
|
done := make(chan bool)
|
||||||
|
go func() {
|
||||||
|
for !c.doneLogging {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
done <- true
|
||||||
|
}()
|
||||||
|
|
||||||
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) logStderr(r io.Reader) {
|
func (c *client) logStderr(r io.Reader) {
|
||||||
|
@ -125,4 +139,7 @@ func (c *client) logStderr(r io.Reader) {
|
||||||
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flag that we've completed logging for others
|
||||||
|
c.doneLogging = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue