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
684df67c
Commit
684df67c
authored
Jun 02, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioner/shell: Adhere to new communicator API
parent
75074ca9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
27 deletions
+37
-27
provisioner/shell/provisioner.go
provisioner/shell/provisioner.go
+37
-27
No files found.
provisioner/shell/provisioner.go
View file @
684df67c
...
@@ -4,10 +4,13 @@ package shell
...
@@ -4,10 +4,13 @@ package shell
import
(
import
(
"fmt"
"fmt"
"github.com/mitchellh/iochan"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"io"
"log"
"log"
"os"
"os"
"time"
)
)
const
DefaultRemotePath
=
"/tmp/script.sh"
const
DefaultRemotePath
=
"/tmp/script.sh"
...
@@ -52,34 +55,45 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
...
@@ -52,34 +55,45 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
return
return
}
}
command
:=
fmt
.
Sprintf
(
"chmod +x %s && %s"
,
p
.
config
.
RemotePath
,
p
.
config
.
RemotePath
)
// Setup the remote command
log
.
Printf
(
"Executing command: %s"
,
command
)
stdout_r
,
stdout_w
:=
io
.
Pipe
()
cmd
,
err
:=
comm
.
Start
(
command
)
stderr_r
,
stderr_w
:=
io
.
Pipe
()
var
cmd
packer
.
RemoteCmd
cmd
.
Command
=
fmt
.
Sprintf
(
"chmod +x %s && %s"
,
p
.
config
.
RemotePath
,
p
.
config
.
RemotePath
)
cmd
.
Stdout
=
stdout_w
cmd
.
Stderr
=
stderr_w
log
.
Printf
(
"Executing command: %s"
,
cmd
.
Command
)
err
=
comm
.
Start
(
&
cmd
)
if
err
!=
nil
{
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Failed executing command: %s"
,
err
))
ui
.
Error
(
fmt
.
Sprintf
(
"Failed executing command: %s"
,
err
))
return
return
}
}
exit
:=
cmd
.
ExitChan
()
exitChan
:=
make
(
chan
int
,
1
)
stderr
:=
cmd
.
StderrChan
()
stdoutChan
:=
iochan
.
DelimReader
(
stdout_r
,
'\n'
)
stdout
:=
cmd
.
StdoutChan
()
stderrChan
:=
iochan
.
DelimReader
(
stderr_r
,
'\n'
)
go
func
()
{
defer
stdout_w
.
Close
()
defer
stderr_w
.
Close
()
for
!
cmd
.
Exited
{
time
.
Sleep
(
50
*
time
.
Millisecond
)
}
exitChan
<-
cmd
.
ExitStatus
}()
OutputLoop
:
OutputLoop
:
for
{
for
{
select
{
select
{
case
output
,
ok
:=
<-
stderr
:
case
output
:=
<-
stderrChan
:
if
!
ok
{
ui
.
Say
(
output
)
stderr
=
nil
case
output
:=
<-
stdoutChan
:
}
else
{
ui
.
Say
(
output
)
ui
.
Say
(
output
)
case
exitStatus
:=
<-
exitChan
:
}
case
output
,
ok
:=
<-
stdout
:
if
!
ok
{
stdout
=
nil
}
else
{
ui
.
Say
(
output
)
}
case
exitStatus
:=
<-
exit
:
log
.
Printf
(
"shell provisioner exited with status %d"
,
exitStatus
)
log
.
Printf
(
"shell provisioner exited with status %d"
,
exitStatus
)
break
OutputLoop
break
OutputLoop
}
}
...
@@ -87,15 +101,11 @@ OutputLoop:
...
@@ -87,15 +101,11 @@ OutputLoop:
// Make sure we finish off stdout/stderr because we may have gotten
// Make sure we finish off stdout/stderr because we may have gotten
// a message from the exit channel first.
// a message from the exit channel first.
if
stdout
!=
nil
{
for
output
:=
range
stdoutChan
{
for
output
:=
range
stdout
{
ui
.
Say
(
output
)
ui
.
Say
(
output
)
}
}
}
if
stderr
!=
nil
{
for
output
:=
range
stderrChan
{
for
output
:=
range
stderr
{
ui
.
Say
(
output
)
ui
.
Say
(
output
)
}
}
}
}
}
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