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
a46c7afc
Commit
a46c7afc
authored
Aug 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioner/shell: retry the upload if command fails as well
This improves reboot handling robustness
parent
251abc34
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
provisioner/shell/provisioner.go
provisioner/shell/provisioner.go
+18
-14
No files found.
provisioner/shell/provisioner.go
View file @
a46c7afc
...
...
@@ -236,17 +236,6 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
}
defer
f
.
Close
()
log
.
Printf
(
"Uploading %s => %s"
,
path
,
p
.
config
.
RemotePath
)
err
=
p
.
retryable
(
func
()
error
{
return
comm
.
Upload
(
p
.
config
.
RemotePath
,
f
)
})
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error uploading shell script: %s"
,
err
)
}
// Close the original file since we copied it
f
.
Close
()
// Flatten the environment variables
flattendVars
:=
strings
.
Join
(
envVars
,
" "
)
...
...
@@ -259,16 +248,31 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
return
fmt
.
Errorf
(
"Error processing command: %s"
,
err
)
}
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
command
}
log
.
Printf
(
"Executing command: %s"
,
cmd
.
Command
)
// Upload the file and run the command. Do this in the context of
// a single retryable function so that we don't end up with
// the case that the upload succeeded, a restart is initiated,
// and then the command is executed but the file doesn't exist
// any longer.
var
cmd
*
packer
.
RemoteCmd
err
=
p
.
retryable
(
func
()
error
{
if
_
,
err
:=
f
.
Seek
(
0
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
comm
.
Upload
(
p
.
config
.
RemotePath
,
f
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Error uploading script: %s"
,
err
)
}
cmd
=
&
packer
.
RemoteCmd
{
Command
:
command
}
return
cmd
.
StartWithUi
(
comm
,
ui
)
})
if
err
!=
nil
{
return
err
}
// Close the original file since we copied it
f
.
Close
()
if
cmd
.
ExitStatus
!=
0
{
return
fmt
.
Errorf
(
"Script exited with non-zero exit status: %d"
,
cmd
.
ExitStatus
)
}
...
...
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