-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstep_shutdown.go
37 lines (34 loc) · 1010 Bytes
/
step_shutdown.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"time"
)
type stepShutdown struct {
}
func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
// c := state.Get("config").(config)
comm := state.Get("communicator").(packer.Communicator)
ui.Say("Shutting down the server...")
cmd := &packer.RemoteCmd{
Command: fmt.Sprintf("shutdown -P"),
}
if err := comm.Start(cmd); err != nil {
cmd = &packer.RemoteCmd{
Command: fmt.Sprintf("sudo shutdown -P"),
}
if errs := comm.Start(cmd); errs != nil {
err_msg := fmt.Errorf("Error could not shutdown server safely: %s (%s)", err,errs)
state.Put("error", err_msg)
ui.Error(err_msg.Error())
return multistep.ActionHalt
}
}
ui.Say("Waiting 20 seconds for server to properly shutdown...")
time.Sleep(20*time.Second)
return multistep.ActionContinue
}
func (s *stepShutdown) Cleanup(state multistep.StateBag) {
}