@ -19,9 +19,16 @@ type ShutdownConfig struct {
// Specify a VM guest shutdown command. VMware guest tools are used by
// default.
Command string ` mapstructure:"shutdown_command" `
// Amount of time to wait for graceful VM shutdown. Examples 45s and 10m.
// Defaults to 5m (5 minutes) .
// Amount of time to wait for graceful VM shutdown.
// Defaults to 5m or five minutes .
Timeout time . Duration ` mapstructure:"shutdown_timeout" `
// 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 five minutes until the virtual machine is shutdown.
// The timeout can be changed using `shutdown_timeout` option.
DisableShutdown bool ` mapstructure:"disable_shutdown" `
}
func ( c * ShutdownConfig ) Prepare ( ) [ ] error {
@ -43,7 +50,15 @@ func (s *StepShutdown) Run(ctx context.Context, state multistep.StateBag) multis
comm := state . Get ( "communicator" ) . ( packer . Communicator )
vm := state . Get ( "vm" ) . ( * driver . VirtualMachine )
if s . Config . Command != "" {
if off , _ := vm . IsPoweredOff ( ) ; off {
// Probably power off initiated by last provisioner, though disable_shutdown is not set
ui . Say ( "VM is already powered off" )
return multistep . ActionContinue
}
if s . Config . DisableShutdown {
ui . Say ( "Automatic shutdown disabled. Please shutdown virtual machine." )
} else if s . Config . Command != "" {
ui . Say ( "Executing shutdown command..." )
log . Printf ( "Shutdown command: %s" , s . Config . Command )
@ -59,7 +74,7 @@ func (s *StepShutdown) Run(ctx context.Context, state multistep.StateBag) multis
return multistep . ActionHalt
}
} else {
ui . Say ( "Shut down VM...")
ui . Say ( "Shut ting down VM...")
err := vm . StartShutdown ( )
if err != nil {