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
19b6841e
Commit
19b6841e
authored
Jul 31, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/common: channels instead of unsafe read/write for communicate
parent
dfbea5e6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
9 deletions
+10
-9
builder/common/step_connect_ssh.go
builder/common/step_connect_ssh.go
+10
-9
No files found.
builder/common/step_connect_ssh.go
View file @
19b6841e
...
@@ -34,8 +34,7 @@ type StepConnectSSH struct {
...
@@ -34,8 +34,7 @@ type StepConnectSSH struct {
// SSHWaitTimeout is the total timeout to wait for SSH to become available.
// SSHWaitTimeout is the total timeout to wait for SSH to become available.
SSHWaitTimeout
time
.
Duration
SSHWaitTimeout
time
.
Duration
cancel
bool
comm
packer
.
Communicator
comm
packer
.
Communicator
}
}
func
(
s
*
StepConnectSSH
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
func
(
s
*
StepConnectSSH
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
...
@@ -44,10 +43,11 @@ func (s *StepConnectSSH) Run(state map[string]interface{}) multistep.StepAction
...
@@ -44,10 +43,11 @@ func (s *StepConnectSSH) Run(state map[string]interface{}) multistep.StepAction
var
comm
packer
.
Communicator
var
comm
packer
.
Communicator
var
err
error
var
err
error
cancel
:=
make
(
chan
struct
{})
waitDone
:=
make
(
chan
bool
,
1
)
waitDone
:=
make
(
chan
bool
,
1
)
go
func
()
{
go
func
()
{
ui
.
Say
(
"Waiting for SSH to become available..."
)
ui
.
Say
(
"Waiting for SSH to become available..."
)
comm
,
err
=
s
.
waitForSSH
(
state
)
comm
,
err
=
s
.
waitForSSH
(
state
,
cancel
)
waitDone
<-
true
waitDone
<-
true
}()
}()
...
@@ -70,13 +70,13 @@ WaitLoop:
...
@@ -70,13 +70,13 @@ WaitLoop:
break
WaitLoop
break
WaitLoop
case
<-
timeout
:
case
<-
timeout
:
ui
.
Error
(
"Timeout waiting for SSH."
)
ui
.
Error
(
"Timeout waiting for SSH."
)
s
.
cancel
=
true
close
(
cancel
)
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
case
<-
time
.
After
(
1
*
time
.
Second
)
:
case
<-
time
.
After
(
1
*
time
.
Second
)
:
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
];
ok
{
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
];
ok
{
// The step sequence was cancelled, so cancel waiting for SSH
// The step sequence was cancelled, so cancel waiting for SSH
// and just start the halting process.
// and just start the halting process.
s
.
cancel
=
true
close
(
cancel
)
log
.
Println
(
"Interrupt detected, quitting waiting for SSH."
)
log
.
Println
(
"Interrupt detected, quitting waiting for SSH."
)
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -89,16 +89,16 @@ WaitLoop:
...
@@ -89,16 +89,16 @@ WaitLoop:
func
(
s
*
StepConnectSSH
)
Cleanup
(
map
[
string
]
interface
{})
{
func
(
s
*
StepConnectSSH
)
Cleanup
(
map
[
string
]
interface
{})
{
}
}
func
(
s
*
StepConnectSSH
)
waitForSSH
(
state
map
[
string
]
interface
{})
(
packer
.
Communicator
,
error
)
{
func
(
s
*
StepConnectSSH
)
waitForSSH
(
state
map
[
string
]
interface
{}
,
cancel
<-
chan
struct
{}
)
(
packer
.
Communicator
,
error
)
{
handshakeAttempts
:=
0
handshakeAttempts
:=
0
var
comm
packer
.
Communicator
var
comm
packer
.
Communicator
for
{
for
{
time
.
Sleep
(
5
*
time
.
Second
)
select
{
case
<-
cancel
:
if
s
.
cancel
{
log
.
Println
(
"SSH wait cancelled. Exiting loop."
)
log
.
Println
(
"SSH wait cancelled. Exiting loop."
)
return
nil
,
errors
.
New
(
"SSH wait cancelled"
)
return
nil
,
errors
.
New
(
"SSH wait cancelled"
)
case
<-
time
.
After
(
5
*
time
.
Second
)
:
}
}
// First we request the TCP connection information
// First we request the TCP connection information
...
@@ -130,6 +130,7 @@ func (s *StepConnectSSH) waitForSSH(state map[string]interface{}) (packer.Commun
...
@@ -130,6 +130,7 @@ func (s *StepConnectSSH) waitForSSH(state map[string]interface{}) (packer.Commun
SSHConfig
:
sshConfig
,
SSHConfig
:
sshConfig
,
}
}
log
.
Println
(
"Attempting SSH connection..."
)
comm
,
err
=
ssh
.
New
(
config
)
comm
,
err
=
ssh
.
New
(
config
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"SSH handshake err: %s"
,
err
)
log
.
Printf
(
"SSH handshake err: %s"
,
err
)
...
...
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