The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/4426

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
LXD_SOCKET overrides whatever socket path would normally be used.

Closes #4422

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From f9f2cafa489983ca858275085715ac3cf06da38d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Mon, 9 Apr 2018 02:49:34 +0200
Subject: [PATCH] client: Introduce LXD_SOCKET
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

LXD_SOCKET overrides whatever socket path would normally be used.

Closes #4422

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 client/connection.go       | 18 +++++++++++-------
 lxd/daemon.go              |  6 ++++++
 lxd/endpoints/endpoints.go |  8 +++++++-
 lxd/endpoints/local.go     |  5 +----
 4 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/client/connection.go b/client/connection.go
index 27d64b7bf8..a2ebbdc5f6 100644
--- a/client/connection.go
+++ b/client/connection.go
@@ -65,8 +65,9 @@ func ConnectLXD(url string, args *ConnectionArgs) 
(ContainerServer, error) {
 
 // ConnectLXDUnix lets you connect to a remote LXD daemon over a local unix 
socket.
 //
-// If the path argument is empty, then $LXD_DIR/unix.socket will be used.
-// If that one isn't set either, then the path will default to 
/var/lib/lxd/unix.socket.
+// If the path argument is empty, then $LXD_SOCKET will be used, if
+// unset $LXD_DIR/unix.socket will be used and if that one isn't set
+// either, then the path will default to /var/lib/lxd/unix.socket.
 func ConnectLXDUnix(path string, args *ConnectionArgs) (ContainerServer, 
error) {
        logger.Debugf("Connecting to a local LXD over a Unix socket")
 
@@ -84,12 +85,15 @@ func ConnectLXDUnix(path string, args *ConnectionArgs) 
(ContainerServer, error)
 
        // Determine the socket path
        if path == "" {
-               lxdDir := os.Getenv("LXD_DIR")
-               if lxdDir == "" {
-                       lxdDir = "/var/lib/lxd"
+               path = os.Getenv("LXD_SOCKET")
+               if path == "" {
+                       lxdDir := os.Getenv("LXD_DIR")
+                       if lxdDir == "" {
+                               lxdDir = "/var/lib/lxd"
+                       }
+
+                       path = filepath.Join(lxdDir, "unix.socket")
                }
-
-               path = filepath.Join(lxdDir, "unix.socket")
        }
 
        // Setup the HTTP client
diff --git a/lxd/daemon.go b/lxd/daemon.go
index 4328953dc8..a045bb3396 100644
--- a/lxd/daemon.go
+++ b/lxd/daemon.go
@@ -216,6 +216,11 @@ func (d *Daemon) State() *state.State {
 // UnixSocket returns the full path to the unix.socket file that this daemon is
 // listening on. Used by tests.
 func (d *Daemon) UnixSocket() string {
+       path := os.Getenv("LXD_SOCKET")
+       if path != "" {
+               return path
+       }
+
        return filepath.Join(d.os.VarDir, "unix.socket")
 }
 
@@ -443,6 +448,7 @@ func (d *Daemon) init() error {
        /* Setup the web server */
        config := &endpoints.Config{
                Dir:                  d.os.VarDir,
+               UnixSocket:           d.UnixSocket(),
                Cert:                 certInfo,
                RestServer:           RestServer(d),
                DevLxdServer:         DevLxdServer(d),
diff --git a/lxd/endpoints/endpoints.go b/lxd/endpoints/endpoints.go
index 75894398a4..4b4192670f 100644
--- a/lxd/endpoints/endpoints.go
+++ b/lxd/endpoints/endpoints.go
@@ -19,6 +19,9 @@ type Config struct {
        // The LXD var directory to create Unix sockets in.
        Dir string
 
+       // UnixSocket is the path to the Unix socket to bind
+       UnixSocket string
+
        // HTTP server handling requests for the LXD RESTful API.
        RestServer *http.Server
 
@@ -87,6 +90,9 @@ func Up(config *Config) (*Endpoints, error) {
        if config.Dir == "" {
                return nil, fmt.Errorf("no directory configured")
        }
+       if config.UnixSocket == "" {
+               return nil, fmt.Errorf("no unix socket configured")
+       }
        if config.RestServer == nil {
                return nil, fmt.Errorf("no REST server configured")
        }
@@ -148,7 +154,7 @@ func (e *Endpoints) up(config *Config) error {
                logger.Infof("LXD isn't socket activated")
                e.listeners = map[kind]net.Listener{}
 
-               e.listeners[local], err = localCreateListener(config.Dir, 
config.LocalUnixSocketGroup)
+               e.listeners[local], err = 
localCreateListener(config.UnixSocket, config.LocalUnixSocketGroup)
                if err != nil {
                        return fmt.Errorf("local endpoint: %v", err)
                }
diff --git a/lxd/endpoints/local.go b/lxd/endpoints/local.go
index c91db701e4..59ef1edf7e 100644
--- a/lxd/endpoints/local.go
+++ b/lxd/endpoints/local.go
@@ -2,13 +2,10 @@ package endpoints
 
 import (
        "net"
-       "path/filepath"
 )
 
 // Create a new net.Listener bound to the unix socket of the local endpoint.
-func localCreateListener(dir string, group string) (net.Listener, error) {
-       path := filepath.Join(dir, "unix.socket")
-
+func localCreateListener(path string, group string) (net.Listener, error) {
        err := CheckAlreadyRunning(path)
        if err != nil {
                return nil, err
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to