Commit cf732a91 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

provisioner/shell: stream output in real time

parent bf296b39
...@@ -36,6 +36,8 @@ func (p *Provisioner) Prepare(raw interface{}, ui packer.Ui) { ...@@ -36,6 +36,8 @@ func (p *Provisioner) Prepare(raw interface{}, ui packer.Ui) {
} }
func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) { func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
ui.Say(fmt.Sprintf("Provisioning with shell script: %s", p.config.Path))
log.Printf("Opening %s for reading", p.config.Path) log.Printf("Opening %s for reading", p.config.Path)
f, err := os.Open(p.config.Path) f, err := os.Open(p.config.Path)
if err != nil { if err != nil {
...@@ -58,7 +60,29 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) { ...@@ -58,7 +60,29 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
return return
} }
ui.Say("Waiting for remote command to finish...") exit := cmd.ExitChan()
cmd.Wait() stderr := cmd.StderrChan()
ui.Say("Command run!") stdout := cmd.StdoutChan()
for {
select {
case output := <-stderr:
ui.Say(output)
case output := <-stdout:
ui.Say(output)
case exitStatus := <-exit:
log.Printf("shell provisioner exited with status %d", exitStatus)
break
}
}
// Make sure we finish off stdout/stderr because we may have gotten
// a message from the exit channel first.
for output := range stdout {
ui.Say(output)
}
for output := range stderr {
ui.Say(output)
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment