Skip to content

Commit

Permalink
Merge pull request #15 from vultr/shutdown_fix
Browse files Browse the repository at this point in the history
manually shutdown instead of halt api
  • Loading branch information
ddymko authored Sep 11, 2019
2 parents a026b37 + 7c55e78 commit c54209e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions vultr/step_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,29 @@ type stepShutdown struct {
}

func (s *stepShutdown) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
c := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui)

ui.Say("Performing graceful shutdown...")
time.Sleep(ShutdownDelaySec * time.Second)
id := state.Get("server_id").(string)
ui.Say("Performing graceful shutdown...")

err := s.client.Server.Halt(context.Background(), id)
comm := state.Get("communicator").(packer.Communicator)

if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
cmd := &packer.RemoteCmd{
Command: "shutdown -P now",
}

err = waitForServerState("active", "stopped", id, s.client, c.stateTimeout)
if err != nil {
if err := comm.Start(ctx, cmd); err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
cmd.Wait()

if cmd.ExitStatus() == packer.CmdDisconnect {
ui.Say("Server successfully shutdown")
time.Sleep(ShutdownDelaySec * time.Second)
} else {
ui.Say("Sleeping to ensure that server is shut down...")
}

return multistep.ActionContinue
}
Expand Down

0 comments on commit c54209e

Please # to comment.