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
020e719e
Commit
020e719e
authored
Jul 14, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
communicator/ssh: re-establish ssh connection if possible [GH-152]
parent
04463f82
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
4 deletions
+23
-4
communicator/ssh/communicator.go
communicator/ssh/communicator.go
+23
-4
No files found.
communicator/ssh/communicator.go
View file @
020e719e
...
...
@@ -46,7 +46,7 @@ func New(config *Config) (result *comm, err error) {
}
func
(
c
*
comm
)
Start
(
cmd
*
packer
.
RemoteCmd
)
(
err
error
)
{
session
,
err
:=
c
.
client
.
N
ewSession
()
session
,
err
:=
c
.
n
ewSession
()
if
err
!=
nil
{
return
}
...
...
@@ -77,7 +77,6 @@ func (c *comm) Start(cmd *packer.RemoteCmd) (err error) {
// exit boolean and status.
go
func
()
{
defer
session
.
Close
()
err
:=
session
.
Wait
()
cmd
.
ExitStatus
=
0
if
err
!=
nil
{
...
...
@@ -94,8 +93,7 @@ func (c *comm) Start(cmd *packer.RemoteCmd) (err error) {
}
func
(
c
*
comm
)
Upload
(
path
string
,
input
io
.
Reader
)
error
{
log
.
Println
(
"Opening new SSH session"
)
session
,
err
:=
c
.
client
.
NewSession
()
session
,
err
:=
c
.
newSession
()
if
err
!=
nil
{
return
err
}
...
...
@@ -190,16 +188,37 @@ func (c *comm) Download(string, io.Writer) error {
panic
(
"not implemented yet"
)
}
func
(
c
*
comm
)
newSession
()
(
*
ssh
.
Session
,
error
)
{
log
.
Println
(
"opening new ssh session"
)
session
,
err
:=
c
.
client
.
NewSession
()
if
err
!=
nil
{
if
err
:=
c
.
reconnect
();
err
!=
nil
{
return
nil
,
err
}
return
c
.
client
.
NewSession
()
}
return
session
,
nil
}
func
(
c
*
comm
)
reconnect
()
(
err
error
)
{
if
c
.
conn
!=
nil
{
c
.
conn
.
Close
()
}
log
.
Printf
(
"reconnecting to TCP connection for SSH"
)
c
.
conn
,
err
=
c
.
config
.
Connection
()
if
err
!=
nil
{
log
.
Printf
(
"reconnection error: %s"
,
err
)
return
}
log
.
Printf
(
"handshaking with SSH"
)
c
.
client
,
err
=
ssh
.
Client
(
c
.
conn
,
c
.
config
.
SSHConfig
)
if
err
!=
nil
{
log
.
Printf
(
"handshake error: %s"
,
err
)
}
return
}
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