2019-05-31 08:27:41 -04:00
|
|
|
//go:generate struct-markdown
|
|
|
|
|
2013-12-22 12:37:27 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2019-10-31 10:49:34 -04:00
|
|
|
"time"
|
2015-05-27 17:01:08 -04:00
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2013-12-22 12:37:27 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type ShutdownConfig struct {
|
2019-05-28 11:50:58 -04:00
|
|
|
// The command to use to gracefully shut down the
|
2019-06-06 10:29:25 -04:00
|
|
|
// machine once all the provisioning is done. By default this is an empty
|
|
|
|
// string, which tells Packer to just forcefully shut down the machine unless a
|
|
|
|
// shutdown command takes place inside script so this may safely be omitted. If
|
|
|
|
// one or more scripts require a reboot it is suggested to leave this blank
|
|
|
|
// since reboots may fail and specify the final shutdown command in your
|
|
|
|
// last script.
|
|
|
|
ShutdownCommand string `mapstructure:"shutdown_command" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The amount of time to wait after executing the
|
2019-06-06 10:29:25 -04:00
|
|
|
// shutdown_command for the virtual machine to actually shut down. If it
|
|
|
|
// doesn't shut down in this time, it is an error. By default, the timeout is
|
|
|
|
// 5m or five minutes.
|
2019-10-31 10:49:34 -04:00
|
|
|
ShutdownTimeout time.Duration `mapstructure:"shutdown_timeout" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The amount of time to wait after shutting
|
2019-06-06 10:29:25 -04:00
|
|
|
// down the virtual machine. If you get the error
|
|
|
|
// Error removing floppy controller, you might need to set this to 5m
|
|
|
|
// or so. By default, the delay is 0s or disabled.
|
2019-10-31 10:49:34 -04:00
|
|
|
PostShutdownDelay time.Duration `mapstructure:"post_shutdown_delay" required:"false"`
|
2019-12-05 08:34:56 -05:00
|
|
|
// Packer normally halts the virtual machine after all provisioners have
|
|
|
|
// run when no `shutdown_command` is defined. If this is set to `true`, Packer
|
|
|
|
// *will not* halt the virtual machine but will assume that you will send the stop
|
|
|
|
// signal yourself through the preseed.cfg or your final provisioner.
|
|
|
|
// Packer will wait for a default of 5 minutes until the virtual machine is shutdown.
|
|
|
|
// The timeout can be changed using `shutdown_timeout` option.
|
|
|
|
DisableShutdown bool `mapstructure:"disable_shutdown" required:"false"`
|
2013-12-22 12:37:27 -05:00
|
|
|
}
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error {
|
2019-10-31 10:49:34 -04:00
|
|
|
if c.ShutdownTimeout == 0 {
|
|
|
|
c.ShutdownTimeout = 5 * time.Minute
|
2013-12-22 12:37:27 -05:00
|
|
|
}
|
|
|
|
|
2019-12-13 04:47:19 -05:00
|
|
|
if c.PostShutdownDelay == 0 {
|
|
|
|
c.PostShutdownDelay = 2 * time.Second
|
|
|
|
}
|
|
|
|
|
2019-10-31 10:49:34 -04:00
|
|
|
return nil
|
2013-12-22 12:37:27 -05:00
|
|
|
}
|