Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #151 from clearcontainers/sboeuf/fix_cli
Browse files Browse the repository at this point in the history
agent-cli: Allow reconnection to the agent
  • Loading branch information
Graham Whaley authored Nov 13, 2017
2 parents c91e4ab + 7fc9f71 commit 243e2ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion hack/agent-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ cc-agent

From a different shell on the host (as root):
```
# ./agent-cli run --ctl=/tmp/hyper.sock --tty=/tmp/tty.sock
# ./agent-cli run --ctl=/tmp/hyper.sock --tty=/tmp/tty.sock --wait-for-ready
```

Do not use the `--wait-for-ready` flag when the `agent-cli` is terminated or disconnected from the `CTL` and `TTY` sockets and the agent is still listening on those sockets. In this case, the agent will not send a `READY` message.

## Usage

### Basics
Expand Down
24 changes: 16 additions & 8 deletions hack/agent-cli/agent_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,21 @@ func monitorStdInLoop(h *hyperstart.Hyperstart, done chan<- bool) error {
}
}

done <- true
close(done)

return nil
}

func monitorTtyOutLoop(h *hyperstart.Hyperstart, done chan<- bool) error {
for {
msgCh := make(chan *hyperstart.TtyMessage, 1)
errorCh := make(chan bool, 1)
msgCh := make(chan *hyperstart.TtyMessage)
errorCh := make(chan bool)

go func() {
msg, err := h.ReadIoMessage()
if err != nil {
magicLog("%s\n", err)
errorCh <- true
close(errorCh)
return
}

Expand All @@ -257,7 +258,7 @@ func monitorTtyOutLoop(h *hyperstart.Hyperstart, done chan<- bool) error {
case msg := <-msgCh:
dumpFrame(*msg)
case <-errorCh:
done <- true
close(done)
break
}
}
Expand All @@ -266,6 +267,7 @@ func monitorTtyOutLoop(h *hyperstart.Hyperstart, done chan<- bool) error {
func mainLoop(c *cli.Context) error {
ctlSockPath := c.String("ctl")
ttySockPath := c.String("tty")
waitForReady := c.Bool("wait-for-ready")

if ctlSockPath == "" || ttySockPath == "" {
return fmt.Errorf("Missing socket path: please provide CTL and TTY socket paths")
Expand All @@ -278,11 +280,13 @@ func mainLoop(c *cli.Context) error {
}
defer h.CloseSockets()

if err := h.WaitForReady(); err != nil {
return err
if waitForReady {
if err := h.WaitForReady(); err != nil {
return err
}
}

done := make(chan bool, 1)
done := make(chan bool)

go monitorStdInLoop(h, done)
go monitorTtyOutLoop(h, done)
Expand Down Expand Up @@ -313,6 +317,10 @@ func main() {
Value: "",
Usage: "the TTY socket path",
},
cli.BoolFlag{
Name: "wait-for-ready",
Usage: "boolean flag to wait for READY message first",
},
},
Action: func(context *cli.Context) error {
return mainLoop(context)
Expand Down

0 comments on commit 243e2ae

Please sign in to comment.