Skip to content

Instantly share code, notes, and snippets.

@cmars
Last active January 19, 2016 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmars/c66665ccb6abc6082168 to your computer and use it in GitHub Desktop.
Save cmars/c66665ccb6abc6082168 to your computer and use it in GitHub Desktop.
Juju sockets proof-of-concept

This is a proof of concept demonstrating local socket communication with Juju using generally available command line utilities and commands from a remote shell via 'juju ssh' or 'juju run'.

package main
import (
"fmt"
"log"
"net"
"time"
"github.com/juju/juju/juju/sockets"
)
func main() {
l, err := sockets.Listen(socketPath)
if err != nil {
panic(err)
}
log.Println("listening on:", socketPath)
for {
c, err := l.Accept()
if err != nil {
panic(err)
}
handle(c)
}
}
func handle(c net.Conn) {
defer c.Close()
err := c.SetDeadline(time.Now().Add(3 * time.Second))
if err != nil {
log.Printf("failed to set deadline: %v", err)
return
}
_, err = fmt.Fprintf(c, "%v\n", time.Now())
if err != nil {
log.Printf("failed to write response: %v", err)
return
}
log.Println("ok")
}
// +build !windows
package main
var socketPath = "/var/tmp/socky.sock"
// +build windows
package main
var socketPath = `\\.\pipe\socky`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment