5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 16:31:41 +00:00

Add support for UNIX domain admin sockets and specifying URIs in AdminListen

This commit is contained in:
Neil Alexander 2018-07-07 11:22:49 +01:00
parent adc21baa28
commit cd6030ec8f
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -229,13 +229,26 @@ func (a *admin) start() error {
// listen is run by start and manages API connections. // listen is run by start and manages API connections.
func (a *admin) listen() { func (a *admin) listen() {
l, err := net.Listen("tcp", a.listenaddr) var l net.Listener
u, err := url.Parse(a.listenaddr)
if err == nil {
switch strings.ToLower(u.Scheme) {
case "unix":
l, err = net.Listen("unix", a.listenaddr[7:])
case "tcp":
l, err = net.Listen("tcp", u.Host)
default:
err = errors.New("protocol not supported")
}
} else {
l, err = net.Listen("tcp", a.listenaddr)
}
if err != nil { if err != nil {
a.core.log.Printf("Admin socket failed to listen: %v", err) a.core.log.Printf("Admin socket failed to listen: %v", err)
os.Exit(1) os.Exit(1)
} }
a.core.log.Printf("%s admin socket listening on %s", strings.ToUpper(l.Addr().Network()), l.Addr().String())
defer l.Close() defer l.Close()
a.core.log.Printf("Admin socket listening on %s", l.Addr().String())
for { for {
conn, err := l.Accept() conn, err := l.Accept()
if err == nil { if err == nil {