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'.
Juju sockets proof-of-concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// +build !windows | |
package main | |
var socketPath = "/var/tmp/socky.sock" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// +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