Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
4af230a4
Commit
4af230a4
authored
Sep 04, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/digitalocean: actually, we want to try hard on shutdown
parent
39f7a5a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
30 deletions
+43
-30
builder/digitalocean/step_power_off.go
builder/digitalocean/step_power_off.go
+22
-22
builder/digitalocean/step_shutdown.go
builder/digitalocean/step_shutdown.go
+21
-8
No files found.
builder/digitalocean/step_power_off.go
View file @
4af230a4
...
...
@@ -15,31 +15,31 @@ func (s *stepPowerOff) Run(state multistep.StateBag) multistep.StepAction {
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
dropletId
:=
state
.
Get
(
"droplet_id"
)
.
(
uint
)
// Gracefully power off the droplet. We have to retry this a number
// of times because sometimes it says it completed when it actually
// did absolutely nothing (*ALAKAZAM!* magic!). We give up after
// a pretty arbitrary amount of time.
var
err
error
ui
.
Say
(
"Gracefully shutting down droplet..."
)
for
attempts
:=
1
;
attempts
<=
10
;
attempts
++
{
log
.
Printf
(
"PowerOffDroplet attempt #%d..."
,
attempts
)
err
:=
client
.
PowerOffDroplet
(
dropletId
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error powering off droplet: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHal
t
}
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
,
20
*
time
.
Second
)
if
err
==
nil
{
// We reached the state!
break
}
_
,
status
,
err
:=
client
.
DropletStatus
(
dropletId
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error checking droplet state: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
if
status
==
"off"
{
// Droplet is already off, don't do anything
return
multistep
.
ActionContinue
}
// Pull the plug on the Drople
t
ui
.
Say
(
"Forcefully shutting down Droplet..."
)
err
=
client
.
PowerOffDroplet
(
dropletId
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error powering off droplet: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
,
20
*
time
.
Second
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for droplet to become 'off': %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
...
...
builder/digitalocean/step_shutdown.go
View file @
4af230a4
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
type
stepShutdown
struct
{}
...
...
@@ -14,17 +15,29 @@ func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction {
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
dropletId
:=
state
.
Get
(
"droplet_id"
)
.
(
uint
)
err
:=
client
.
ShutdownDroplet
(
dropletId
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error shutting down droplet: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
// Gracefully power off the droplet. We have to retry this a number
// of times because sometimes it says it completed when it actually
// did absolutely nothing (*ALAKAZAM!* magic!). We give up after
// a pretty arbitrary amount of time.
var
err
error
ui
.
Say
(
"Gracefully shutting down droplet..."
)
for
attempts
:=
1
;
attempts
<=
10
;
attempts
++
{
log
.
Printf
(
"ShutdownDropetl attempt #%d..."
,
attempts
)
err
:=
client
.
ShutdownDroplet
(
dropletId
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error shutting down droplet: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
,
c
.
stateTimeout
)
if
err
==
nil
{
break
}
}
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
,
c
.
stateTimeout
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for droplet to become 'off': %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment