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
b64a2532
Commit
b64a2532
authored
Jul 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioner/shell: use StartWithUi
parent
56cf09f2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
51 deletions
+4
-51
provisioner/shell/provisioner.go
provisioner/shell/provisioner.go
+4
-51
No files found.
provisioner/shell/provisioner.go
View file @
b64a2532
...
...
@@ -7,10 +7,8 @@ import (
"bytes"
"errors"
"fmt"
"github.com/mitchellh/iochan"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
"io"
"io/ioutil"
"log"
"os"
...
...
@@ -221,59 +219,14 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
t
:=
template
.
Must
(
template
.
New
(
"command"
)
.
Parse
(
p
.
config
.
ExecuteCommand
))
t
.
Execute
(
&
command
,
&
ExecuteCommandTemplate
{
flattendVars
,
p
.
config
.
RemotePath
})
// Setup the remote command
stdout_r
,
stdout_w
:=
io
.
Pipe
()
stderr_r
,
stderr_w
:=
io
.
Pipe
()
var
cmd
packer
.
RemoteCmd
cmd
.
Command
=
command
.
String
()
cmd
.
Stdout
=
stdout_w
cmd
.
Stderr
=
stderr_w
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
command
.
String
()}
log
.
Printf
(
"Executing command: %s"
,
cmd
.
Command
)
err
=
comm
.
Start
(
&
cmd
)
if
err
!=
nil
{
if
err
:=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed executing command: %s"
,
err
)
}
exitChan
:=
make
(
chan
int
,
1
)
stdoutChan
:=
iochan
.
DelimReader
(
stdout_r
,
'\n'
)
stderrChan
:=
iochan
.
DelimReader
(
stderr_r
,
'\n'
)
go
func
()
{
defer
stdout_w
.
Close
()
defer
stderr_w
.
Close
()
cmd
.
Wait
()
exitChan
<-
cmd
.
ExitStatus
}()
OutputLoop
:
for
{
select
{
case
output
:=
<-
stderrChan
:
ui
.
Message
(
strings
.
TrimSpace
(
output
))
case
output
:=
<-
stdoutChan
:
ui
.
Message
(
strings
.
TrimSpace
(
output
))
case
exitStatus
:=
<-
exitChan
:
log
.
Printf
(
"shell provisioner exited with status %d"
,
exitStatus
)
if
exitStatus
!=
0
{
return
fmt
.
Errorf
(
"Script exited with non-zero exit status: %d"
,
exitStatus
)
}
break
OutputLoop
}
}
// Make sure we finish off stdout/stderr because we may have gotten
// a message from the exit channel first.
for
output
:=
range
stdoutChan
{
ui
.
Message
(
output
)
}
for
output
:=
range
stderrChan
{
ui
.
Message
(
output
)
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