2013-05-11 13:46:17 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cmdHook struct {
|
2013-05-20 19:50:35 -04:00
|
|
|
hook packer.Hook
|
2013-06-11 14:03:36 -04:00
|
|
|
client *Client
|
2013-05-11 13:46:17 -04:00
|
|
|
}
|
|
|
|
|
2013-06-26 20:50:25 -04:00
|
|
|
func (c *cmdHook) Run(name string, ui packer.Ui, comm packer.Communicator, data interface{}) error {
|
2013-05-11 13:46:17 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
c.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
2013-06-26 20:50:25 -04:00
|
|
|
return c.hook.Run(name, ui, comm, data)
|
2013-05-11 13:46:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cmdHook) checkExit(p interface{}, cb func()) {
|
|
|
|
if c.client.Exited() {
|
|
|
|
cb()
|
2013-08-20 02:38:22 -04:00
|
|
|
} else if p != nil && !Killed {
|
2013-05-11 13:46:17 -04:00
|
|
|
log.Panic(p)
|
|
|
|
}
|
|
|
|
}
|